microsoft / microsoft/vscode-cpptools

References and Call Hierarchy are wrong for constructors

Aperta
#14,629 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug Feature: Call Hierarchy Feature: Find All References Language Service
Lingua principale
TypeScript
Stelle
6.2k
Fork
1.7k
Merge medio
14h 46m
PR unite (30g)
61

Descrizione

Environment

cpptools — References and Call Hierarchy are wrong for the constructor ui::Widget::Widget(int)

Field Value
Symbol (spec id) ctor-Widget-int
Declaration explicit Widget(int id);
Query position src/widget.h:13:14 (cursor on Widget)
Affected LSP requests textDocument/references, callHierarchy/incomingCalls
Repro archive P1-P1-ctor-Widget-int.zip (this folder)

Summary

Two independent defects hit the same constructor when it is queried in VS Code with the C/C++ extension (cpptools):

  1. Find All References returns every mention of the Widget type instead of the actual construction sites (over-count).
  2. Show Call Hierarchy → Show Incoming Calls returns nothing, so the constructor looks like it is never called (false "no callers").

The correct (expected) results are shown below.

Environment

  • Editor: Visual Studio Code 1.33.5
  • Extension: C/C++ (ms-vscode.cpptools), default IntelliSense engine
  • Language standard: C++20 — the fixture is freestanding (no STL/toolchain needed to parse)

Steps to reproduce

  1. Extract P1-P1-ctor-Widget-int.zip and open the cpp-project folder in VS Code with the C/C++ extension enabled.
  2. Optionally configure with CMake Tools (preset cdb) so cpptools picks up compile_commands.json; the freestanding fixture also parses under default C++20 IntelliSense.
  3. Open src/widget.h, place the cursor on Widget in explicit Widget(int id); (line 13, col 14).

Adding a full repro in P1-ctor-Widget-int.zip attached file.
P1-ctor-Widget-int.zip

Defect 1 — textDocument/references
  1. Invoke Find All References (Shift+Alt+F12).
Source Result count
Expected 4
VS Code / cpptools 28

Expected (4): the declaration (widget.h:13), the out-of-line definition (widget.cpp:9, Widget::Widget(int id)), and the two Widget(int) construction sites in main.cpp — the static ui::Widget storage(42); initializer in allocWidget() and ui::Widget b(7); in main().

Actual (28): every occurrence of the ui::Widget type — the typedef, the g_current pointer, the takeWidget/makeDefault/allocWidget/asConst parameter and return types, the Serializer<ui::Widget> specialization, and the type-mention lines in widget.cpp — none of which construct an object. A references query on the constructor collapses to "every mention of the enclosing type."

Defect 2 — callHierarchy/incomingCalls
  1. With the cursor at the same position, invoke Show Call Hierarchy and expand Incoming Calls.
Source Result count
Expected 2
VS Code / cpptools 0

Expected (2): incoming calls from allocWidget() (the storage(42) construction at main.cpp:29) and from main() (the b(7) construction at main.cpp:55).

Actual (0): the Call Hierarchy view shows no callers, i.e. the constructor appears to be dead.

Why it matters

  • The empty incoming-calls result is a false "no callers" on live code: an automated agent (or a developer) can conclude Widget(int) is never used and delete/prune construction paths that are actually exercised.
  • The reference over-count means "where is this object constructed?" cannot be answered, the list is dominated by unrelated type mentions.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Estrai P1-ctor-Widget-int.zip e riproduci le query da src/widget.h confrontandole con i siti di costruzione in main.cpp e con la definizione in widget.cpp. Confronta textDocument/references e callHierarchy/incomingCalls con i conteggi attesi documentati. Il lavoro è completato quando il costruttore restituisce solo la propria dichiarazione, definizione e due siti di costruzione, e compaiono entrambi i chiamanti in ingresso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, typescript
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
52/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.