Vscode-cpptools: Duplicate symbols listed in "@" symbol search when symbol is being used in function prototype or typedef(Ctrl-Shift-O)

Created on 1 Sep 2018  路  6Comments  路  Source: microsoft/vscode-cpptools

Type: LanguageService

Describe the bug

  • OS and Version: Arch x64 (Linux 4.18.3)
  • VS Code Version: 1.26.1
  • C/C++ Extension Version: 0.18.1
  • Other extensions you installed (and if the issue persists after disabling them): None
  • A clear and concise description of what the bug is:

The symbol search function in the command pallette (Ctrl-Shift-O) lists symbols which are return values of functions, resulting in duplicate symbols being listed (legitimate definitions and those in function prototypes/declarations).

To Reproduce

  1. Create a new empty .h file.
  2. Create a struct tag definition, with optional fields.
  3. Write a prototype for a function that returns the said struct (or perhaps a pointer to said struct)
  4. Open the symbol search with Ctrl-Shift-O or type the @ symbol in the command pallette
  5. Type the name of the defined struct
  6. Observe that 2 symbols will be listed, one referencing the actual tag definition, and one referencing the prototype of the function

Expected behavior

Only one symbol is listed in the search, pointing to the definition of the struct tag.

Screenshots

2018-09-01_1535834397_588x173
Screenshot showing multiple flag symbols, only the first of which belongs to the definition of the struct flag.

Additional context

c_cpp_properties.json
This issue is present anywhere that symbols are listed. Including but not limited to @ cmd palette search, # cmd palette search, OUTLINE Explorer View, Alt+N symbol view, etc...

Language Service Visual Studio bug

All 6 comments

Any progress on confirming my issue?

Are you also defining an alias for the struct? I don't repro with the following code:

struct A {};
A* get_A();
void main()
{
    A* asdf = get_A();
}

but I do with the following (which is currently the expected behavior):

typedef struct A {} A;
A* get_A();
void main()
{
    A* asdf = get_A();
}

Can you share a code snippet that manifests your problem?

The following snippet, when saved as a .h file, gives the following results in OUTLINE view, Ctrl+O symbol search, Alt+N search and Ctrl + T symbol search:

struct flag {
    int a;
};

typedef struct flag Flag;

const struct flag *fget(int a, int b, int c);

2018-09-18_1537270058_599x124

The first flag symbol belongs to the struct tag definition, which is OK, but the 2nd and 3rd belong to the typedef and the function prototype, respectively. The capitalized Flag is expected, as it's a separate type definition.

It seems that struct tag definitions get picked up as duplicated symbols when included in function prototypes. (e.g. from your example, A* get_A(); doesn't produce a duplicate as A is typdef'd, but struct A* get_A(); does), and in typedef definitions.

I believe only one flag symbol should be listed, no?

Oh, I see. Yeah, it's probably because of the struct keyword before each reference to flag. We'll investigate.

VS 2017 shows similar results for global symbols, although they don't seem to have an Outline view. Yeah, looks like our symbol parser or our usage isn't correctly handling the C-style "struct name" usage.

We have improved the scenario via adding (declaration) to the instances that are declaration, but there is still a bug with the use of "struct s" as a type (not a declaration). It's being tracked by https://developercommunity.visualstudio.com/content/problem/456439/cc-intellisense-incorrectly-treats-struct-mystruct.html so you can upvote that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ismadelgad11 picture ismadelgad11  路  3Comments

jrieken picture jrieken  路  3Comments

SkyRiderMike picture SkyRiderMike  路  3Comments

vicatcu picture vicatcu  路  3Comments

thndrwrks picture thndrwrks  路  3Comments