Allow forward-declaration of elaborated types in type decls
This covers the common C pattern of declaring a typedef for a struct before the struct itself, e.g. typedef struct foo foo_t; struct foo { int value; foo_t *next; }; Fixes issue #1065.
This commit is contained in:
parent
0f7a7aba8c
commit
d2d4d15d8d
5
iwyu.cc
5
iwyu.cc
|
@ -170,6 +170,7 @@ using clang::Decl;
|
|||
using clang::DeclContext;
|
||||
using clang::DeclRefExpr;
|
||||
using clang::DeducedTemplateSpecializationType;
|
||||
using clang::ElaboratedType;
|
||||
using clang::EnumConstantDecl;
|
||||
using clang::EnumDecl;
|
||||
using clang::EnumType;
|
||||
|
@ -2610,6 +2611,10 @@ class IwyuBaseAstVisitor : public BaseAstVisitor<Derived> {
|
|||
}
|
||||
|
||||
parent_type = GetTypeOf(decl);
|
||||
} else if (ast_node->IsA<ElaboratedType>()) {
|
||||
// If it's not a ValueDecl, it must be a type decl. Elaborated types in
|
||||
// type decls are forward-declarable.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,14 @@ int UseStruct(struct Struct* s);
|
|||
struct ForwardDeclared;
|
||||
void UseForwardDeclared(struct ForwardDeclared*);
|
||||
|
||||
// If a forward-declaration is seen before an actual struct declaration in the
|
||||
// same file, no diagnostic is expected (see issue #1065).
|
||||
typedef struct local_struct local_struct_t;
|
||||
struct local_struct {
|
||||
int x;
|
||||
local_struct_t* next;
|
||||
};
|
||||
|
||||
/**** IWYU_SUMMARY
|
||||
|
||||
tests/c/elaborated_struct.c should add these lines:
|
||||
|
|
Loading…
Reference in New Issue