Skip to content

Deal with clang-generated name collisions #1307

@edsko

Description

@edsko

Given

struct foo { char a; char b; };
typedef struct { double x; double y; } foo;

clang-16 and up assign the name foo to the anonymous struct (older versions return an empty string), resulting in name clashes when we construct the DeclIndex (which will then throw out both struct foos, and then selection will throw out the typedef also due to missing transitive dependency). This is a bit frustrating, because in HandleTypedefs we will then squash the second struct foo, and the name clash would disappear again.

If we theoretically would squash the typedef as we process it, we would avoid the issue. In practice, this is hard to do: we use the UseDecl graph to find out which structs have exactly one use site, and we don't have the UseDecl graph until parsing is complete. Just to be explicit, during parsing, instead of

typedef struct { double x; double y; } foo;

we will see

typedef struct foo { double x; double y; } foo;

so it's not a priori clear that this struct cannot have other use sites (if we could reliably detect anonymous structs we could do better, but we can't; that's precisely the problem). See also detailed discussion in #1292.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions