diff --git a/iwyu.cc b/iwyu.cc index e3849cf..0147718 100644 --- a/iwyu.cc +++ b/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 { } parent_type = GetTypeOf(decl); + } else if (ast_node->IsA()) { + // If it's not a ValueDecl, it must be a type decl. Elaborated types in + // type decls are forward-declarable. + return true; } } diff --git a/tests/c/elaborated_struct.c b/tests/c/elaborated_struct.c index 941ad69..5ef008c 100644 --- a/tests/c/elaborated_struct.c +++ b/tests/c/elaborated_struct.c @@ -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: