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

Find references doesn't find struct member initializers

Open smoofra opened this issue 6 years ago • 5 comments

Type: LanguageService

Describe the bug

  • OS and Version: Mac OS Catalina
  • VS Code Version: 1.37.1
  • C/C++ Extension Version: 0.25.1

To Reproduce

struct foo { 
    int some_field;
};

void bar() { 
    struct foo x = {
        .some_field = 1
    };
    x.some_field = 2;
}
  1. Invoke "Find All References" on some_field in line 2
  2. It will find the assignment (line 9), but not the initializer (line 7)

Expected behavior Find references should have found both references to some_field

It should also be able to find

struct foo x = {1};

smoofra avatar Aug 30 '19 20:08 smoofra

The bug is inherited from VS. I've filed bug https://developercommunity.visualstudio.com/content/problem/718983/cc-designated-initializers-dont-appear-as-confirme.html .

The reference is reported as "Not A Reference" in the Output pane.

I'm not sure if "struct foo x = {1};" counts as a reference though.

sean-mcmanus avatar Aug 30 '19 21:08 sean-mcmanus

In my opinion = {1} should also count, because it's initializing that specific field. I don't think that = {} should count though.

smoofra avatar Aug 30 '19 21:08 smoofra

excuse me ! how can i get the struct's member's references, such like "some_field"? I'm newer, i have tried some ways, but not work. thanks!

taihangg avatar Jan 19 '21 09:01 taihangg

@taihangg Just do a Find All References: image

This issue is on the fact that the initializer is reported as "Not a Reference".

sean-mcmanus avatar Jan 20 '21 23:01 sean-mcmanus

I wasn't able to reproduce with a test case so I'm not filing a new bug, but this is probably related:

The reference to emulate on this line: https://github.com/dsalt/devilspie2/blob/760df8ce0db8f51c75acbb27ab0e420174cb8352/src/devilspie2.c#L321 also triggers the "NOT A REFERENCE" behavior when doing "Find All References" on another reference to emulate.

My example and this whole bug may also be related to #4083

sparr avatar Oct 04 '24 12:10 sparr

The original problem reported in this issue appears to be fixed in the latest version of the extension.

@sparr I tried something similar to what that file you referenced is doing since I'm not set up for IntelliSense for that project. With my trimmed down version, the reference was correctly reported, but if this is still a bug for you, please open a new issue.

EDIT: this is what I tried @sparr

bool emulate;

typedef struct {
    bool *hi;
} foo2;

int main() {
    foo2 f = { &emulate };
}

bobbrow avatar Nov 27 '24 23:11 bobbrow