Skip to content

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

Open
@samkearney

Description

@samkearney

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions