Linux: Incorrect Intelli-Sense Error: global wchar_t array initialized with wide character string literal
samival opened this issue · comments
Environment
- OS and Version: Linux (Ubuntu based 22.04 & 20.04 on WSL)
- VS Code Version: 1.91.1
- C/C++ Extension Version: 2.0.0
Bug Summary and Steps to Reproduce
Steps to reproduce:
Create a .c file with a global wchar_t array and initialize it with a wide char string literal (L"..." )
i.e. wchar_t s[] = L"ABC";
Bug Summary:
On Linux the Intelli-Sense Engine seems to identify wide-character string literals as unsigned int
arrays while wchar_t
is typedef'd by GCC to be signed int
, causing a type mismatch which triggers an incorrect error.
The error shown is:
a value of type "unsigned int [4]" cannot be used to initialize an entity of type "wchar_t []" (aka "int []")C/C++(144)
Initializing a const wchar_t *
doesn't produce an error.
Initializing in a local scope doesn't produce an error.
Some potentially relevant VSCode settings:
C_Cpp.intelliSenseEngine = deafult
C_Cpp.intelliSenseEngineFallback = disabled
C_Cpp.default.cStandard = C17
(same result for all other available values)
C_Cpp.default.intelliSenseMode = linux-gcc-x64
(or:)
C_Cpp.default.intelliSenseMode = windows-gcc-x64
Configuration and Logs
(some information omitted)
Version: 1.21.3
Current Configuration:
{
"name": "Linux",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64",
"intelliSenseModeIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"mergeConfigurations": false,
}
cpptools version (native): 1.21.3.0
Translation Unit Configurations:
Process ID: 5302
Memory Usage: 18 MB
Compiler Path: /usr/bin/gcc
Includes:
System Includes:
/usr/lib/gcc/x86_64-linux-gnu/9/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
Standard Version: c17
IntelliSense Mode: linux-gcc-x64
Other Flags:
--gcc
--gnu_version=90400
Total Memory Usage: 18 MB
Other Extensions
No response
Additional context
No response
Hi @samival . Thanks for reporting this. I can reproduce the issue. We'll investigate.
When GCC uses the -fshort-wchar
compiler switch (like when compiling U-Boot), Intellisense should be informed about this in the settings of C/C++ Tools extension:
- Find the setting
C_Cpp › Default: Compiler Args
in@ext:ms-vscode.cpptools
- Add
-fshort-wchar
Now, if I write wchar_t* str = L"hehe";
, on hovering over wchar_t
Intellisense correctly says typedef unsigned short wchar_t
. However, hovering over L"hehe"
it says (unsigned int [5])L"hehe"
I wonder if this issue is related to the above one.