You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
c/c++ intellisense Can't resolve c++ stl identifier like "string","map","list"... #11407
If using SSH remote, specify OS of remote machine: yes,Ubuntu 20.04.3
remote gcc version : 9.4.0
Bug Summary and Steps to Reproduce
Bug Summary:
I have been using c/c++ extension for a while,It worked fine.But when c/c++ extension upgrade to 1.17.5, I got this error.The latest workable version is 1.16.3.I roll back to 1.16.3,it works fine.
Steps to reproduce:
I use vscode from window
I use remote-ssh connect to ubuntu 20.04
The compiler on the remote is gcc version 9.4.0
code like this:
#include
using namespace std;
typedef string STRING
it shows : identifier 'string' not defined
Expected behavior:
intellisense does not show compile error.
Configuration and Logs
I can only provide part of c_cpp_properties.json like this by my memory:
"compilerPath": "/usr/bin/g++",
"cStandard": "c17",
"cppStandard": "gnu++11",
"intelliSenseMode": "linux-gcc-x64",
I add a lot of includePath about my project in c_cpp_properties.json
I specific C_Cpp.intellisenseCachePath in${workspaceFolder}/.vscode/.cache and C_Cpp.intellisenseCacheSize = 10240 in settings.json
I turned c/c++ intellisense log level to 'debug' and did not find obvious error in c/c++ output.
Hi cenpengzhu . Thanks for reporting the problem to us. We're not tracking a known issue as general is this. Can you provide a minimal, self-contained example that does not work properly for you, in the form of a zip file or GitHub repo, so we can investigate further?
Hello Colen Garoutte-Carson (@Colengms) , I have figured out something about this problem.I am in China.We use text encoding GB2312 on windows system.But on linux the encoding is going to be UTF-8.
What happened today is that I used vscode to work on other project. It is encode with UTF-8.So I changed the setting named "Files:Encoding" from GB2312 to UTF-8.Then I opened the project with this problem just a few minutes before to collect some info for you.I found the problem disappeared!
After some tries, I get the conclusion here is :
case use c/c++ extension ver 1.16.3, it goes well no matter what the setting "Files:Encoding" is.
case use c/c++ extension ver 1.17.5, it goes wrong with the setting “Files:Encoding” is “GB2312”. It goes well with the setting "Files:Encoding" is "UTF-8"
Actually,most files of my project is encode with GB2312.And I noticed that when the problem occurred , c/c++ log diagnostics show the totally memory usage is only 9 MB while it should has been hundreds MB.
Sorry for providing limit infomation like this.I got this problem in my office dev environment.I can't take files out because of the company's data security rules.Hope it is useful for you.Thanks for your response about this problem.
Hello Colen Garoutte-Carson (@Colengms) , I have figured out something about this problem.I am in China.We use text encoding GB2312 on windows system.But on linux the encoding is going to be UTF-8.
What happened today is that I used vscode to work on other project. It is encode with UTF-8.So I changed the setting named "Files:Encoding" from GB2312 to UTF-8.Then I opened the project with this problem just a few minutes before to collect some info for you.I found the problem disappeared!
After some tries, I get the conclusion here is :
case use c/c++ extension ver 1.16.3, it goes well no matter what the setting "Files:Encoding" is.
case use c/c++ extension ver 1.17.5, it goes wrong with the setting “Files:Encoding” is “GB2312”. It goes well with the setting "Files:Encoding" is "UTF-8"
Actually,most files of my project is encode with GB2312.And I noticed that when the problem occurred , c/c++ log diagnostics show the totally memory usage is only 9 MB while it should has been hundreds MB.
Sorry for providing limit infomation like this.I got this problem in my office dev environment.I can't take files out because of the company's data security rules.Hope it is useful for you.Thanks for your response about this problem.
1.16.3, it goes well no matter what the setting "Files:Encoding" is.
Hi cenpengzhu . The difference in behavior you are seeing is likely due to a recent bug fix in which the files.encoding setting was not being applied. #11210
When VS Code opens a file, it will check for a BOM to determine the encoding. If no BOM is present, and the file is not UTF-16 (which is easy to check for), and files.autoGuessEncoding is enabled, VS Code will perform various other "auto-detection" schemes to determine the encoding of the file, before falling back to the value specified in files.encoding.
When the C/C++ Extension internally opens files to parse them, and those files do not have a BOM and are not UTF-16, it does not currently perform this "auto guess" phase. That is currently being tracked by: #4753 Instead, the C/C++ Extension will go directly to interpreting these files using the files.encoding setting.
If you are indeed seeing an issue in which the files.encoding setting should match the files in your project but you are not seeing the correct behavior, could you isolate this into a simple example that you can provide us for further investigation? I'm not able to easily reproduce this problem myself.
Note that the C/C++ Extension is only using the files.encoding setting to open files directly, such as header files included by a source file currently open, which are not themselves currently open in VS Code. If a file is open in VS Code, those contents are provided to the C/C++ Extension in UTF-8 format, having already been converted to UTF-8 by VS Code.
Since the errors you are reporting are related to standard types (string, map, list), perhaps the issue is because your system headers are UTF-8 and settings files.encoding to something other than UTF-8 will cause them not to be parsed properly.
You might consider updating the file encoding of your project's sources and headers, or your local system headers, to include a BOM. That would remove all ambiguity as to the right encoding to use, as the encoding information would be embedded into those files.
Hello Colen Garoutte-Carson (@Colengms),I think I have understood what you are saying.And I would like to try to make an example reproducing this problem this weekends.
Windows uses GBK or GB2312 as default encoding format for chinese characters.But Linux does not.It caused a lot of problems.
Hello Colen Garoutte-Carson (@Colengms),I think I have understood what you are saying.And I would like to try to make an example reproducing this problem this weekends.
Windows uses GBK or GB2312 as default encoding format for chinese characters.But Linux does not.It caused a lot of problems.
Hello, Colen Garoutte-Carson (@Colengms) ,the problem can not be reproduced on windows platform. So I use WSL building an Ubuntu environment.I connect to Ubuntu environment from vscode on windows and the problem occurs in a very simple
source file.
I installed gcc 9.4.0 on the remote WSL Ubuntu environment.
I have tried to switch "files:encoding" setting several times.And I got a small example video for you.
Hi cenpengzhu . I can reproduce the issue, but I believe the current behavior is by-design and addressing it would require addressing the scenario within VS Code itself. I can reproduce the issue without the C/C++ performing any of its own internal file reads, by also opening the system headers in question into VS Code (causing VS Code to pass those files contents directly to the extension, incorrectly converted to UTF-8). I can see that, due to global setting "files.encoding": "gb2312", those system headers are indeed treated incorrectly as gb2312 files by VS Code. I can similarly reproduce the issue when using a UTF-8 header file from a library, or in the same project, so the issue is not isolated to C/C++ system headers.
In order to fully address your scenario, it would be necessary for VS Code to provide sufficient settings granularity to allow the user to vary the default file encoding across different directories.
Alternatively, the work-around I previously suggested, to manually convert your system headers to UTF-8+BOM or GB2312, or to convert your project sources/headers to UTF-8, UTF-8 + BOM, UTF-16, etc., should also work.
I'd suggest opening an issue in the VS Code repo to point out that a global files.encoding setting is insufficient when using files of a mixture of encodings (UTF-8 system or library headers and GB2313 project sources and headers), and that a folder-granular setting would seem to be required to configure your project correctly. I'd be happy to add clarification to an issue in their repo, to help get this addressed.
One possible approach would be for VS Code to apply the files.encoding setting only to the current workspace, if specified in only that workspace's settings, while applying it to files outside of the workspace only if set globally. (Though, a more granular setting would be more useful.) Unfortunately, that does not appear to be the way that VS Code itself applies this setting, currently.
Activity
Colengms commentedon Sep 5, 2023
Hi cenpengzhu . Thanks for reporting the problem to us. We're not tracking a known issue as general is this. Can you provide a minimal, self-contained example that does not work properly for you, in the form of a zip file or GitHub repo, so we can investigate further?
cenpengzhu commentedon Sep 6, 2023
Hello Colen Garoutte-Carson (@Colengms) , I have figured out something about this problem.I am in China.We use text encoding GB2312 on windows system.But on linux the encoding is going to be UTF-8.
What happened today is that I used vscode to work on other project. It is encode with UTF-8.So I changed the setting named "Files:Encoding" from GB2312 to UTF-8.Then I opened the project with this problem just a few minutes before to collect some info for you.I found the problem disappeared!

After some tries, I get the conclusion here is :
case use c/c++ extension ver 1.16.3, it goes well no matter what the setting "Files:Encoding" is.
case use c/c++ extension ver 1.17.5, it goes wrong with the setting “Files:Encoding” is “GB2312”. It goes well with the setting "Files:Encoding" is "UTF-8"
Actually,most files of my project is encode with GB2312.And I noticed that when the problem occurred , c/c++ log diagnostics show the totally memory usage is only 9 MB while it should has been hundreds MB.
Sorry for providing limit infomation like this.I got this problem in my office dev environment.I can't take files out because of the company's data security rules.Hope it is useful for you.Thanks for your response about this problem.
cenpengzhu commentedon Sep 6, 2023
Hello Colen Garoutte-Carson (@Colengms) , I have figured out something about this problem.I am in China.We use text encoding GB2312 on windows system.But on linux the encoding is going to be UTF-8.
What happened today is that I used vscode to work on other project. It is encode with UTF-8.So I changed the setting named "Files:Encoding" from GB2312 to UTF-8.Then I opened the project with this problem just a few minutes before to collect some info for you.I found the problem disappeared!

After some tries, I get the conclusion here is :
case use c/c++ extension ver 1.16.3, it goes well no matter what the setting "Files:Encoding" is.
case use c/c++ extension ver 1.17.5, it goes wrong with the setting “Files:Encoding” is “GB2312”. It goes well with the setting "Files:Encoding" is "UTF-8"
Actually,most files of my project is encode with GB2312.And I noticed that when the problem occurred , c/c++ log diagnostics show the totally memory usage is only 9 MB while it should has been hundreds MB.
Sorry for providing limit infomation like this.I got this problem in my office dev environment.I can't take files out because of the company's data security rules.Hope it is useful for you.Thanks for your response about this problem.
Colengms commentedon Sep 6, 2023
Hi cenpengzhu . The difference in behavior you are seeing is likely due to a recent bug fix in which the
files.encodingsetting was not being applied. #11210When VS Code opens a file, it will check for a BOM to determine the encoding. If no BOM is present, and the file is not UTF-16 (which is easy to check for), and
files.autoGuessEncodingis enabled, VS Code will perform various other "auto-detection" schemes to determine the encoding of the file, before falling back to the value specified infiles.encoding.When the C/C++ Extension internally opens files to parse them, and those files do not have a BOM and are not UTF-16, it does not currently perform this "auto guess" phase. That is currently being tracked by: #4753 Instead, the C/C++ Extension will go directly to interpreting these files using the
files.encodingsetting.If you are indeed seeing an issue in which the
files.encodingsetting should match the files in your project but you are not seeing the correct behavior, could you isolate this into a simple example that you can provide us for further investigation? I'm not able to easily reproduce this problem myself.Note that the C/C++ Extension is only using the
files.encodingsetting to open files directly, such as header files included by a source file currently open, which are not themselves currently open in VS Code. If a file is open in VS Code, those contents are provided to the C/C++ Extension in UTF-8 format, having already been converted to UTF-8 by VS Code.Since the errors you are reporting are related to standard types (string, map, list), perhaps the issue is because your system headers are UTF-8 and settings
files.encodingto something other than UTF-8 will cause them not to be parsed properly.You might consider updating the file encoding of your project's sources and headers, or your local system headers, to include a BOM. That would remove all ambiguity as to the right encoding to use, as the encoding information would be embedded into those files.
cenpengzhu commentedon Sep 7, 2023
Hello Colen Garoutte-Carson (@Colengms),I think I have understood what you are saying.And I would like to try to make an example reproducing this problem this weekends.
Windows uses GBK or GB2312 as default encoding format for chinese characters.But Linux does not.It caused a lot of problems.
Thanks for your response!
cenpengzhu commentedon Sep 7, 2023
Hello Colen Garoutte-Carson (@Colengms),I think I have understood what you are saying.And I would like to try to make an example reproducing this problem this weekends.
Windows uses GBK or GB2312 as default encoding format for chinese characters.But Linux does not.It caused a lot of problems.
Thanks for your response!
cenpengzhu commentedon Sep 11, 2023
Hello, Colen Garoutte-Carson (@Colengms) ,the problem can not be reproduced on windows platform. So I use WSL building an Ubuntu environment.I connect to Ubuntu environment from vscode on windows and the problem occurs in a very simple

source file.
I installed gcc 9.4.0 on the remote WSL Ubuntu environment.
I have tried to switch "files:encoding" setting several times.And I got a small example video for you.
example_video.mp4
Hope it is useful for you.
Colengms commentedon Sep 11, 2023
Hi cenpengzhu . I can reproduce the issue, but I believe the current behavior is by-design and addressing it would require addressing the scenario within VS Code itself. I can reproduce the issue without the C/C++ performing any of its own internal file reads, by also opening the system headers in question into VS Code (causing VS Code to pass those files contents directly to the extension, incorrectly converted to UTF-8). I can see that, due to global setting
"files.encoding": "gb2312", those system headers are indeed treated incorrectly asgb2312files by VS Code. I can similarly reproduce the issue when using a UTF-8 header file from a library, or in the same project, so the issue is not isolated to C/C++ system headers.In order to fully address your scenario, it would be necessary for VS Code to provide sufficient settings granularity to allow the user to vary the default file encoding across different directories.
Alternatively, the work-around I previously suggested, to manually convert your system headers to UTF-8+BOM or GB2312, or to convert your project sources/headers to UTF-8, UTF-8 + BOM, UTF-16, etc., should also work.
I'd suggest opening an issue in the VS Code repo to point out that a global
files.encodingsetting is insufficient when using files of a mixture of encodings (UTF-8 system or library headers and GB2313 project sources and headers), and that a folder-granular setting would seem to be required to configure your project correctly. I'd be happy to add clarification to an issue in their repo, to help get this addressed.One possible approach would be for VS Code to apply the
files.encodingsetting only to the current workspace, if specified in only that workspace's settings, while applying it to files outside of the workspace only if set globally. (Though, a more granular setting would be more useful.) Unfortunately, that does not appear to be the way that VS Code itself applies this setting, currently.github-actions commentedon Nov 11, 2023
This issue has been closed because it needs more information and has not had recent activity.