microsoft / microsoft/vscode-cpptools

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

Offen
#13,685 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug parser Visual Studio
Vorherrschende Sprache
TypeScript
Sterne
6.2k
Forks
1.7k
Ø Merge
14 Std. 46 Min.
Gemergte PRs (30 T.)
61

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das minimale CMake-Projekt zu reproduzieren und die IntelliSense-Wellenlinie mit dem fehlerfreien Ergebnis von GCC zu vergleichen. Verfolge, wie IntelliSense GCC statement expressions behandelt, die einen dynamisch initialisierten local static enthalten, und überprüfe anschließend, dass die Diagnose verschwindet, während gültige Diagnosen erhalten bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
cmake, cpp
Bereich
compilers, developer-experience
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.