Author Topic: autolist doesn't work with structured binding in C++  (Read 1661 times)

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
autolist doesn't work with structured binding in C++
« on: April 17, 2022, 09:01:54 PM »
See example below look for "PROBLEM:"

Code: [Select]
class Item
{
public:
  int itemA;
  int itemB;
};

std::map<std::string, Item> someMap;

void someFunc()
{
  // Iterate over the map using structured binding
  for (auto& [key, value] : someMap) {
    // PROBLEM: After typing the dot I expect to have an autolist of itemA, itemB but don't get the autolist.
    value. 
  }
   
}

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: autolist doesn't work with structured binding in C++
« Reply #1 on: April 17, 2022, 09:36:25 PM »
I wonder if this could be because I'm using a very old gcc (4.8.2) for my C/C++ compiler configuration tag file?

My project is using a newer compiler (gcc 10.2 and clang 13.0.0).

Maybe I should try creating a new tag file with gcc 10.2 and not use the 4.8.2 one. Will try that later. Maybe that could explain, or maybe not.

But this could be problematic because my CentOS system has gcc 4.8 in /usr/include, but gcc 10.2 system header files are in a dedicated directory.

Does it mean I'd have to figure out what in /usr/include is from gcc 4.8.2, remove that and then add all gcc 10.2 header files into my C/C++ Compiler configuration tag files? It may be difficult to figure out what in /usr/include is from gcc and what else is system header files (like pthread, etc).

I think all C++ .h files are under /usr/include/c++/4.8.2, so maybe remove just those and then add my .h from dedicated gcc 10.2 dir?
« Last Edit: April 17, 2022, 09:41:45 PM by rowbearto »

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: autolist doesn't work with structured binding in C++
« Reply #2 on: April 18, 2022, 01:54:24 PM »
If gcc 10.2 is in your path, when you do an Add from the C/C++ compiler configuration dialog, it should find that installation.  Is that not working for you?

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: autolist doesn't work with structured binding in C++
« Reply #3 on: April 18, 2022, 02:27:15 PM »
gcc 10.2 is NOT in my PATH. gcc 4.8.2 is in my PATH, as it is the default compiler on our CentOS 7.2 systems.

The product I'm building has 3 build targets, clang13/x86_64, gcc10.2/x86, gcc10.2/arm.

When a particular build target is chosen, the build scripts put that compiler's bin in the PATH only during the build, inside the build script.

But I do need to browse the code for this product. Nothing I work on uses the system's 4.8.2 compiler.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: autolist doesn't work with structured binding in C++
« Reply #4 on: April 25, 2022, 03:46:20 PM »
So what is the best way to proceed here?

If I put gcc 10.2 in my PATH temporarily and launch SE will I have a tagfile for the system gcc 4.8.2 and another tagfile for the gcc 10.2?

What about my other system header files that are in /usr/include, would they only be in the gcc 4.8.2 tagfile?

If I have 2 tagfiles, one for 4.8.2+system headers and another for gcc 10.2 would they conflict?

My current mindset is that I should take my system tagfile that currently has gcc 4.8.2, remove all the .h from gcc for C and C++, and then add into this tagfile the .h from gcc 10.2? Then I have the gcc I want in my tagfile and I also have all the system headers?

Actually my target has a sysroot for cross-compilation, maybe I should get all system header files from there instead? But I have different targets with different sysroots, so I suppose have to pick one?

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: autolist doesn't work with structured binding in C++
« Reply #5 on: April 25, 2022, 04:51:30 PM »
This is the intention behind the C/C++ Compiler Configuration options.  You can create a separate Compiler Configuration for GCC 10.2, and then in the projects that use that compiler, you can go to Project Properties... > Compile / Link and specify that.  Context Tagging selects the active Compiler Configuration from the project setup, or uses the default if you have no project open.  The Compiler Configuration can even be set per build configuration.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: autolist doesn't work with structured binding in C++
« Reply #6 on: May 04, 2022, 02:50:49 AM »
So I tried putting my gcc 10.2 in the PATH, but SE didn't pick it up when creating a "Compiler Configuration Tag File"
I think it may be because the gcc executable is called 'i686-cp-linux-gnu-gcc' and not just "gcc"? I don't know?
I put this gcc into my PATH and launched SE.
Then I did Tools->Tag Files
Pushed the button "Automatically build tag files for language specific libraries"
It did not find my special gcc 10.2.

So then I manually created a C/C++ tag file from the directory containing gcc 10.2.

So now in SE's "Tag Files" window, I see 2 different areas for C/C++:

"C/C++ Compiler Configuration Tag Files" : This has the system gcc 4.8 compiler that I don't want
"C/C++  Tag Files": This has the gcc 10.2 compiler that I do want.

If I want to set globally to use the tag file for gcc 10.2, then I would uncheck the tagfile for 4.8?

But when I try to uncheck it refuses and says: "Can not change active compiler configuration here, use Project Properties dialog".

So then I go into the Project Properties/Compile/Link tab, but my new tagfile is not in the dropdown for "Compiler:"

So somehow I have to tell SE that this is a compiler tag file. But when I have it in my PATH then SE doesn't see it? Maybe because the name of the gcc is "i686-cp-linux-gnu-gcc" and not just "gcc"? I don't know?

How to tell SE that the tagfile I manually created is a "Compiler tag file" and not just a regular C/C++ tag file?

But even if I could do that, I have many many SE projects. Do I have to go into each one of them, and each configuration in them and tell it to use this compiler?

I'd additionally like an option of a global setting where I tell all my C/C++ projects which compiler to use?
« Last Edit: May 04, 2022, 03:07:51 AM by rowbearto »

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: autolist doesn't work with structured binding in C++
« Reply #7 on: May 04, 2022, 03:13:40 AM »
OK So I found in Project Properties the ... menu for the compiler in Compile/Link tab.

This allows me to add a compiler configuration.

It wants the built-in compiler include directories.

So I found a command to enumerate them:

Code: [Select]
echo | /path/to/i686-cp-linux-gnu-g++ -E -Wp,-v -
Then I added each of these include directories to this new configuration.

Will see how it goes.

I made it the default configuration.

Does it mean I have to go into all my existing project files and change the compiler? I never messed with this setting before, I wasn't so detailed about it.

Is there a simple way to make all of my projects use this if I never touched that setting in project properties before?


Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: autolist doesn't work with structured binding in C++
« Reply #8 on: May 04, 2022, 01:22:36 PM »
If you go to Document > C/C++ Options..., there is an options page for Compiler Properties.  Starting SlickEdit with your gcc 10.2 on your path, if you click on "Add..." to add a new configuration, if SlickEdit can detect your installation (I think this does depend on the bin/ directory having a gcc or g++), then it should be there for you to add.  SlickEdit does this auto-detection once, so that's why you would have to hit add to find additional compiler installations if you need to add one after the fact.  If it detects something new, you will get a dialog box "Add Compilers" with a list of compiler names.  If there is nothing new, then it will prompt you for the name of a compiler to add manually. 

The compiler configurations are stored in your configuration directory (compilers.xml).

The setting in the XML project files (*.vpj) for compiler configuration is "CompilerConfigName", which is per-configuration.  There is some logic built-in if you set the project compiler configuration setting to "Default Compiler" or "Latest Version" to select the default compiler configuration (as set up on the C/C++ Compiler Properties dialog) or the configuration that SlickEdit is able to parse out with the highest version number (that parsing is somewhat specific to how SlickEdit detects and names compiler configurations).

You could edit all your project files and set "CompilerConfigName" to your 10.2 configuration name, or the "Default Compiler", or to "Latest Version" to use that configuration consistently across all projects.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: autolist doesn't work with structured binding in C++
« Reply #9 on: May 04, 2022, 01:38:04 PM »
I'll try this later. But was thinking that if I could somehow tell you the full path of my gcc or clang executable then SE could run it to find out its built-in include paths and add that compiler. This way if my gcc has some other name, like i686-cp-linux-gnu-gcc then SE could easily add this compiler and its include paths.

Giving the full path to my compiler binary also has the advantage that I don't have to change my PATH to run SE just for it to 'maybe' find this compiler.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: autolist doesn't work with structured binding in C++
« Reply #10 on: May 13, 2022, 12:42:51 PM »
Back to the original reported issue, I now have gcc 10.2 as the default C/C++ Compiler Configuration tag file.

The original reported issue is still there, even with using gcc 10.2 as the library.

Press the 'dot' after 'value' and I don't get the autolist choices.

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: autolist doesn't work with structured binding in C++
« Reply #11 on: May 13, 2022, 01:20:44 PM »
I do have this on my list to look into.  This is a really complex case.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: autolist doesn't work with structured binding in C++
« Reply #12 on: May 19, 2022, 01:04:44 AM »
When I used the clangd LSP (language server protocol) with this structured binding example it is able to autolist after typing the 'dot'. clangd has already solved this 'tricky' issue - wish it was better integrated with SE (vs using my own limited SE macro to interface with clangd).

I concur with this post in another thread: https://community.slickedit.com/index.php/topic,16666.msg74764.html#msg74764

It really is essential for SlickEdit to support LSP with clangd. clangd already has this 'tricky' issue (basic iteration of map with key, value) solved and has an army of developers maintaining clangd. I am easily able to tell clangd the compiler commands for all source files (json file generated by cmake), so clangd knows all of my defined/undefined macros for each and every source file and exactly how I do the build. clangd easily handles my project of 18K source files. When I try to go to definition of an overloaded function or macro, SlickEdit lists many possible matches, clangd takes me to the exact one so I don't have to figure it out. Don't get me wrong the SE parser is still good and has some better features in some areas, but having SlickEdit support BOTH clangd LSP AND its own tagging would SOOO sweet! As said in the other post clangd uses a real compiler with knowledge of all the compiler command lines - that is extremely powerful!