Author Topic: can't jump to definition of std::string_view  (Read 3969 times)

Offline mayaming

  • Single posting newcomer
  • *
  • Posts: 4
can't jump to definition of std::string_view
« on: September 26, 2024, 06:55:28 am »
hi,

I'm new to code blocks. I write my first cpp console application but can't jump to declaration or implementation of std::string_view when I right click those menu items. Meanwhile, it works for std::string. Since string_view is supported since c++ 17, I'm wondering if it is because codeblock doesn't support declaration or implementation jumping for those added after c++ 17?

The "-std=c++20" option is checked in compiler settings and it could build and run correctly. My g++ version is:

g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Here's the code:
Code
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s("Hello world!");
    string_view sv(s.c_str(), 5);
    cout <<sv <<endl;
    return 0;
}

Thanks!


 

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1634
Re: can't jump to definition of std::string_view
« Reply #1 on: September 26, 2024, 03:43:59 pm »
The "legacy" Code Completion plugin cannot cope with the complexities of recent C++ standards. The Clangd-plugin should work, but only recent C::B versions incluye it (you did not specify your C::B version).

Look for Clangd in the wiki for more information.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: can't jump to definition of std::string_view
« Reply #2 on: September 26, 2024, 03:49:01 pm »
What is your C::B version? Maybe you can try the clangd_client plugin.

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline mayaming

  • Single posting newcomer
  • *
  • Posts: 4
Re: can't jump to definition of std::string_view
« Reply #3 on: September 27, 2024, 01:27:40 pm »
Thanks Gimenez and ollydbg! Here's my C::B information, Build Sep 14 2024:

Name                   : Code::Blocks
Version                : svn-r13570
SDK Version            : 2.25.0
Scintilla Version      : 3.7.5
Author                 : The Code::Blocks Team
E-mail                 : info@codeblocks.org
Website                : https://www.codeblocks.org
OS                     : Linux 6.8.0-45-generic x86_64
Desktop environment    : GNOME
Scaling factor         : 1.000000
Detected scaling factor: 1.000000
Display PPI            : 96x96
Display count          : 1
Display 0              : XY=[0,0]; Size=[1920,1080]; Primary

wxWidgets Library (wxGTK port)
Version 3.2.2 (Unicode: wchar_t, debug level: 1),
Runtime version of toolkit used is 3.24.
Compile-time GTK+ version is 3.24.36.


I'm using Ubuntu 22.04.5 LTS in a vmware player.

I followed the steps on https://wiki.codeblocks.org/index.php/CB_Clangd_Client. I installed clang-16:

Debian clangd version 16.0.6 (15~deb12u1)
Features: linux+grpc
Platform: x86_64-pc-linux-gnu


But I got stuck in this step:

Navigate to Setting->Plugins->Manage Plugins and enable Clangd_client.

I don't have the "Clangd_client" item to enable. Is it a problem of my C::B version?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: can't jump to definition of std::string_view
« Reply #4 on: September 27, 2024, 02:56:19 pm »

Navigate to Setting->Plugins->Manage Plugins and enable Clangd_client.

I don't have the "Clangd_client" item to enable. Is it a problem of my C::B version?

Where did you install/download the C::B? Do you build it yourself?

It is very strange that you don't have "Clangd_client" plugin installed.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7680
    • My Best Post
Re: can't jump to definition of std::string_view
« Reply #5 on: September 27, 2024, 07:47:56 pm »
I am guessing he needs to install "codeblocks-contrib" package.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline mayaming

  • Single posting newcomer
  • *
  • Posts: 4
Re: can't jump to definition of std::string_view
« Reply #6 on: September 29, 2024, 06:26:37 am »
Here's how to got C::B installed. I added

deb https://apt.xaviou.fr/debian12/ bookworm main
deb-src https://apt.xaviou.fr/debian12/ bookworm main


to my apt source and then installed codeblocks, but I did not install codeblocks-contrib. After I installed it, the "Clangd_Client" plugin appeared and now I can goto implementation of string_view.

After I jumped to the source code of string_view, it's not correctly highlighted (I attached the screen shot), but anyway I can jump to read the source now. Thanks for your help!



Offline mayaming

  • Single posting newcomer
  • *
  • Posts: 4
Re: can't jump to definition of std::string_view
« Reply #7 on: September 30, 2024, 03:19:03 am »
The highlight issue is because string_view header file doesn't have an extension, so it won't be applied with c/c++ syntax highlight. It worked after I added "*" to c/c++ file pattern matching.