vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

gcc emulation: Intellisense produces error where GCC does not in the case of statement expressions

Open samkearney opened this issue 5 months ago • 2 comments

Environment

  • OS and Version: macOS Sequoia 15.5
  • VS Code Version: 1.100.3
  • C/C++ Extension Version: 1.25.3
  • If using SSH remote, specify OS of remote machine: Ubuntu 20.04.6 LTS

Bug Summary and Steps to Reproduce

Bug Summary: When given a minimal program which initializes a static instance of a class inside a GCC statement expression, Intellisense produces an error squiggle while the program compiles cleanly in GCC. This is using GCC 10.5.0 on Ubuntu 20.04 (x86_64).

Steps to reproduce: Create a CMake project with a single C++ file with this content:

class ValueContainer
{
public:
    ValueContainer(int value) : value_(value) {}

private:
    int value_;
};

#define DO_SOMETHING(value) (({ \
    static ValueContainer foo{value}; \
    &foo; \
}))

int main()
{
    DO_SOMETHING(1);
    return 0;
}

Enable the VSCode C++ and CMake Tools extensions on the project.

An error squiggle is seen at line 17 with the message "a dynamically-initialized local static variable is not allowed inside of a statement expressionC/C++(1232)".

Image

The program compiles cleanly with no warnings with GCC either invoked from the command line or via the CMake Tools extension.

Expected behavior: VS Code produces no error squiggles

Configuration and Logs

C++ configured automatically through CMake Tools, the default configuration. Here is a dump from the debug logs:

Custom browse configuration received: {
  "browsePath": [
    "/home/skearney/devenv-wip/vscode-cpp-test"
  ],
  "compilerPath": "/usr/bin/X11/g++",
  "compilerArgs": [],
  "compilerFragments": [
    "-g"
  ]
}

Other Extensions

No response

Additional context

No response

samkearney avatar Jun 10 '25 18:06 samkearney

@samkearney It's a bug with our parser. I've filed an internal issue 2502991 .

sean-mcmanus avatar Jun 10 '25 21:06 sean-mcmanus

@sean-mcmanus Thanks!

samkearney avatar Jun 11 '25 14:06 samkearney