Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellisense with latest standards (e.g. C++20) works at the beginning, but forgets the standard as soon as the file is edited #10953

Closed
codimoc opened this issue May 14, 2023 · 14 comments
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service Not Repro - Internal Verified issue does not reproduce not reproing We're not able to reproduce the issue (it's unlikely to get fixed until we find one).

Comments

@codimoc
Copy link

codimoc commented May 14, 2023

Environment

  • OS and Version: Linux
  • VS Code Version: 1.78.2
  • C/C++ Extension Version: v1.15,4
  • If using SSH remote, specify OS of remote machine:
  • Using CMake

Bug Summary and Steps to Reproduce

Bug Summary:
When setting Intellisense to use C++ 20 standard and displaying a file containing keywords like "concept" or "requires" (which are features in C++20) it works. As soon as the file is edited again, it seems that it is losing the standard and it shows errors on "concept" as missing symbol. Basically it shows errors as if the standard is back to C++ 17. Any action to reload the workspace or to re-save the file .vscode/settings resolves the errors. However they come back as soon as the file is re-edited.

Steps to reproduce:

  1. set Intellisense standard as C++20, for example in settings.json with "C_Cpp.default.cppStandard": "c++20"
  2. write a cpp files containing C++ features, e.g.:
#include <concepts> 

template <typename T> concept Numeric = std::integral<T>|| std::floating_point<T>;
  1. initially all fine. Then add any line and the errors squiggles appears (e.g. concept is not recognized)
  2. re-edit or resave settings.json, or reload workspace and errors disappear
  3. Reproducible over and over

Expected behavior:
Intellisense should continue to work on C++20 standard if this is set

Configuration and Logs

settings.json:

{
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
    "C_Cpp.default.cppStandard": "c++20"
}

no c_cpp_poperty.json but it happened also with this file set

Other Extensions

No response

Additional context

No response

@codimoc codimoc changed the title Intellisense with latest standards (e.g. C++20) works at the beginning, but forgets the standars as soon as the file is edited Intellisense with latest standards (e.g. C++20) works at the beginning, but forgets the standard as soon as the file is edited May 14, 2023
@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented May 15, 2023

Can you run the C/C++: Log Diagnostics command before and after the IntelliSense mode seems to change and see if the Standard Version changes from c++20 to c++17 in the logging? Also, in that logging do you see c++17 in the "Custom configurations:" sections, such as in compilerFragments? Checking if the issue repros when "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" is removed could also help.

@sean-mcmanus sean-mcmanus self-assigned this May 15, 2023
@sean-mcmanus sean-mcmanus added Language Service more info needed The issue report is not actionable in its current state Feature: Configuration An issue related to configuring the extension or IntelliSense labels May 15, 2023
@codimoc
Copy link
Author

codimoc commented May 15, 2023

Thanks Sean. Today it seems that the error squiggles stay there also after a "Reload windows". They are not displayed only when the folder is loaded on start-up. However, apart from date, time and process id, the C++ log diagnostic is basically the same. Here is a copy: Thx

`-------- Diagnostics - 15/05/2023, 19:36:17
Version: 1.15.4
Current Configuration:
{
"name": "Linux",
"includePath": [
"/home/gualtiero/proj/Cpp/cpp_features/"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"compilerPathInCppPropertiesJson": "/usr/bin/clang",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x64",
"intelliSenseModeIsExplicit": true,
"cStandardIsExplicit": false,
"cppStandardIsExplicit": true,
"mergeConfigurations": false,
"compilerPathIsExplicit": false,
"configurationProvider": "ms-vscode.cmake-tools",
"browse": {
"path": [
"${workspaceFolder}/
"
],
"limitSymbolsToIncludedHeaders": true
}
}
Custom browse configuration:
{
"browsePath": [
"/home/gualtiero/proj/Cpp/cpp_features/build/CMakeFiles",
"/home/gualtiero/proj/Cpp/cpp_features/src"
],
"compilerPath": "/usr/bin/g++",
"compilerArgs": [],
"compilerFragments": [
"-g",
"-std=gnu++2a"
]
}
Custom configurations:
[ /home/gualtiero/proj/Cpp/cpp_features/src/concepts.cpp ]
{
"includePath": [],
"defines": [],
"compilerPath": "/usr/bin/g++",
"compilerArgs": [],
"compilerFragments": [
"-g",
"-std=gnu++2a"
]
}
Translation Unit Mappings:
[ /home/gualtiero/proj/Cpp/cpp_features/src/concepts.cpp ]:
/home/gualtiero/proj/Cpp/cpp_features/src/concepts.cpp
Translation Unit Configurations:
[ /home/gualtiero/proj/Cpp/cpp_features/src/concepts.cpp ]:
Process ID: 4164
Memory Usage: 95 MB
Compiler Path: /usr/bin/g++
Includes:
/usr/include/c++/10
/usr/include/x86_64-linux-gnu/c++/10
/usr/include/c++/10/backward
/usr/lib/gcc/x86_64-linux-gnu/10/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
Standard Version: c++20
IntelliSense Mode: linux-gcc-x64
Other Flags:
--g++
--gnu_version=100201
Total Memory Usage: 95 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 20836

`

@sean-mcmanus sean-mcmanus removed the more info needed The issue report is not actionable in its current state label May 15, 2023
@sean-mcmanus
Copy link
Collaborator

Hmm...I'm not reproducing the issue and your logging looks okay. One potential thing to try is setting C_Cpp.intelliSenseCacheSize to 0. Otherwise, I'll see if anyone else on my team can repro this.

@sean-mcmanus sean-mcmanus added the not reproing We're not able to reproduce the issue (it's unlikely to get fixed until we find one). label May 15, 2023
@sean-mcmanus sean-mcmanus added the investigate: repro This issue's repro steps needs to be investigated/confirmed label May 15, 2023
@codimoc
Copy link
Author

codimoc commented May 15, 2023

Thanks Sean. C_Cpp.intelliSenseCacheSize=0 does not solve. To be more precise, as soon as the settings file is changed, the squiggles disappear as if it is working. For any editing of the active cpp file, the squiggles come back.
I wonder: do you have any configuration where you declare a concept in VS C++ and it does not show any error?

Basically, is it possible to have the following without Intellisense squiggles:

#include <concepts>

template<typename T> concept Numeric = std::integral<T> || std::floating_point<T>;

Thanks

@sean-mcmanus
Copy link
Collaborator

Yes, that normally works (it works for us). We're not sure yet why you're seeing an error.

@codimoc
Copy link
Author

codimoc commented May 15, 2023

hmm, that is strange. Have you tried to write a test file test.cpp, with the two lines above. Now, assuming no squiggles, adding an empty line at the end. That, or any other edit, generate the errors. Notice that it only happens with this feature, C++17 features behave well.
Basically I am migrating out of Eclipse CDT and so far VS Code is the best, apart from this. You guys are doing a great work!

@sean-mcmanus
Copy link
Collaborator

It works for me with a nearly identical setup -- the only difference I see is I'm using gcc 10.4 instead of 10.2 -- can you upgrade your gcc to 10.4? It's possible there could be a bug with our handling of 10.2.

@codimoc
Copy link
Author

codimoc commented May 15, 2023

ok, I will see if I can install on Debian 11. Thx

@codimoc
Copy link
Author

codimoc commented May 15, 2023

Hmm, built gcc 10.4 from source, gcc -v shows 10.4 now and in config:
--gnu_version=100400

However the problems remains :(

...And again "Reload Window" or re-saving settings solves the problem until the next edit...

And this is also interesting. When I play with the settings:

  1. "C_Cpp.default.cppStandard": "" -> errors as expected with concept
  2. "C_Cpp.default.cppStandard": "c++20" -> error disappear
  3. edit test.cpp file ->error reappears
  4. "C_Cpp.default.cppStandard": "" -> errors as expected with concept
  5. "C_Cpp.default.cppStandard": "c++20" -> error disappear
  6. ....(cycle on and on)

So this suggest that c++20 works at the begging but then is dropped for any edit action. Really weird

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented May 15, 2023

Do you still have the configurationProvider set? It sounds like you do not.

Are you editing a .cpp or .h file?

@sean-mcmanus sean-mcmanus added To Verify - Internal To verify if issue reproduces and removed investigate: repro This issue's repro steps needs to be investigated/confirmed labels May 15, 2023
@codimoc
Copy link
Author

codimoc commented May 16, 2023

Tried both h and cpp, same problem
I have re-added configurationProvider in local settings:
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}
same problem

Could you please send me a copy of all the settings files you are using: main config setting, local settings and, if present, c_cpp_properties.json? Also, shall I use this file (c_cpp_properties.json) or just the local settings and config settings? Not clear to me

@v-ericawu v-ericawu added Not Repro - Internal Verified issue does not reproduce and removed To Verify - Internal To verify if issue reproduces labels May 16, 2023
@sean-mcmanus
Copy link
Collaborator

@codimoc Unfortunately, our team is still unable to repro this. We're using "C_Cpp.default.cppStandard": "c++20".

The fact that it shows c++20 in the Log Diagnostics logging but the errors are still occurring seems to imply there is some unexpected parsing error.

Can you run /usr/bin/g++ -std=gnu++2a -E ./test.cpp > ./test.out.cpp to generate a preprocessed file and then open the file and see if there are any IntelliSense errors in that file and if the bug repros with that file still? That will rule out any issue related to the headers or our processing of the header.

@codimoc
Copy link
Author

codimoc commented May 16, 2023

No squiggles/ errors in test.out.cpp, even after editing. The file has many lines at the top
(I guess from #include concepts) and ends with:

# 2 "./test.cpp" 2

# 2 "./test.cpp"
template concept Numeric = std::integral|| std::floating_point;

So it looks like as if Intellisense gets confused in parsing my <concepts> while gcc does a good job when it spits it out at the top. Could it be the depth of the cache when parsing many nested #includes?

Maybe this could be a clue. When I check the output for "JSON Language Server" in the bottom output tab, it shows only one line:
cancelled.
Is this normal?

@codimoc
Copy link
Author

codimoc commented May 16, 2023

Wow! I have finally resolved the problem. It was very insidious, and this is the story on how I got it solved:

I have another Linux box with OpenSuse 15.4. Opensuse tends to have old versions, so my gcc was still v7, but I upgraded from source to v10.4, in line with my Debian laptop.
The C++ extension was the same version on the two machines, while VS on OpenSuse was a few main versions behind (but this was not the problem).
Now, I wrote my test.cpp with the "concept" declaration and c++20 standard for Intellisense: on this machine it all worked fine.
Then, by comparing the configuration logs, and trying to make them match with each other, I removed a few setting and realized that my Debian defaults to a clang compiler (not gcc which is the default for the other machine) and that I had a clang installation on Debian. I uninstalled clang and now all my problems on Debian are solved. Hurrah!!

Thanks a lot for the support and the many suggestion given. You helped a lot understanding how it all hang toghether.
This case can now be closed. :)

@sean-mcmanus sean-mcmanus closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service Not Repro - Internal Verified issue does not reproduce not reproing We're not able to reproduce the issue (it's unlikely to get fixed until we find one).
Projects
None yet
Development

No branches or pull requests

4 participants