microsoft / microsoft/vscode-cpptools
Single `#include` inside of array causes VSCode to report the "expected an expression" error
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Environment
- OS and Version: Windows 11 24H2 (Build 26100.4349)
- VS Code Version: 1.101.2
- C/C++ Extension Version: 1.26.3
Bug Summary and Steps to Reproduce
Bug Summary:
I'm currently working on a project that combines an X macro with an #include statement to populate an array from a generated file, like this:
// main.c
#include <stdio.h>
#define X(n) n
int array[] = {
#include "file.txt"
// 0
}; // "expected an expression"
#undef X
int main() {
for (int i = 0; i < 3; i++)
{
printf("%i\n", array[i]); // Output is "123", as expected.
}
return 0;
}
// file.txt
X(1),
X(2),
X(3),
It feels hackish, but it compiles and runs. However, VSCode doesn't seem to like the fact that array has nothing but #include "file.txt" inside. Uncommenting 0 makes the error go away, although, this obviously makes array to have 4 items instead of intended 3.
Steps to reproduce:
- Create
main.candfile.txtand insert code above; - Open
main.cin VSCode; - Notice error on line 7.
Expected behavior:
VSCode should understand that #include "file.txt" with expanded macros provide an expected expression.
Configuration and Logs
-------- Diagnostics - 6/30/2025, 1:54:07 AM
Version: 1.26.3
Current Configuration:
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.26100.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"compilerPathInCppPropertiesJson": "cl.exe",
"intelliSenseModeIsExplicit": false,
"cStandardIsExplicit": false,
"cppStandardIsExplicit": false,
"mergeConfigurations": false,
"recursiveIncludes": {},
"recursiveIncludesReduceIsExplicit": false,
"recursiveIncludesPriorityIsExplicit": false,
"recursiveIncludesOrderIsExplicit": false,
"compilerPathIsExplicit": false,
"browse": {
"limitSymbolsToIncludedHeaders": true
}
}
Modified Settings:
{
"C_Cpp.autocompleteAddParentheses": true,
"C_Cpp.formatting": "clangFormat",
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, AlignAfterOpenBracket: BlockIndent, BinPackArguments: false, PenaltyBreakAssignment: 64 }",
"C_Cpp.codeAnalysis.clangTidy.enabled": true
}
Additional Tracked Settings:
{
"editorTabSize": 4,
"editorInsertSpaces": true,
"editorAutoClosingBrackets": "languageDefined",
"filesEncoding": "utf8",
"filesAssociations": {},
"filesExclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/.DS_Store": true,
"**/Thumbs.db": true
},
"filesAutoSaveAfterDelay": false,
"editorInlayHintsEnabled": true,
"editorParameterHintsEnabled": true,
"searchExclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true
},
"workbenchSettingsEditor": "ui"
}
cpptools version (native): 1.26.3.0
Current database path: C:\USERS\OPERATOR\APPDATA\LOCAL\TEMP\{4514E1A3-0F0D-4E39-A2F4-4D7081E65254}\.BROWSE.VC.DB
Translation Unit Mappings:
[ C:\Users\operator\Desktop\repos\test\main.c - source TU]:
C:\Users\operator\Desktop\repos\test\file.txt
Translation Unit Configurations:
[ C:\Users\operator\Desktop\repos\test\main.c ]
Process ID: 11608
Memory Usage: 63 MB
Compiler Path: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64\cl.exe
Include paths:
include: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\include
include: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include
include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt
include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um
include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared
include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\winrt
include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\cppwinrt
include: C:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.2\Include\um
system include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um
system include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt
system include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared
system include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\winrt
system include: C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\cppwinrt
Defines:
_DEBUG
UNICODE
_UNICODE
Standard Version: ms_c17
IntelliSense Mode: windows-msvc-x64
Other Flags:
--using_directory
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\lib\x86
--using_directory
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\lib\x86\store\references
--using_directory
C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.26100.0
--using_directory
C:\Program Files (x86)\Windows Kits\10\References\10.0.26100.0
--using_directory
C:\Windows\Microsoft.NET\Framework\v4.0.30319
Total Memory Usage: 63 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 5082
Number of files parsed: 238
Other Extensions
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the main.c and file.txt reproducer using the reported VS Code, C/C++ extension, and cl.exe configuration, then compare compiler behavior with the IntelliSense diagnostic. Done means the include-expanded array is accepted without the "expected an expression" error while retaining the three intended elements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100