diff options
author | Bolshakov <bolsh.andrey@yandex.ru> | 2023-04-08 18:43:23 +0300 |
---|---|---|
committer | Kim Gräsman <kim.grasman@gmail.com> | 2023-04-16 16:13:39 +0200 |
commit | c6976de83a0c57cfd45ab4cf62d7bc70752122c5 (patch) | |
tree | 156a2860838437ae0e0af50f593c9beb863cef11 | |
parent | 5957e2fb928d97446a3905d09e6c317960c4622e (diff) |
Fix elaborated type provision by alias
Elaborated types in typedef definitions should not be short-circuited
because they may yet require full-type info according to the IWYU
policy. Otherwise, it can result in a bug when IWYU requires a full type
neither on alias declaration side nor on using side.
-rw-r--r-- | iwyu.cc | 6 | ||||
-rw-r--r-- | tests/cxx/iwyu_stricter_than_cpp-type_alias.h | 5 | ||||
-rw-r--r-- | tests/cxx/iwyu_stricter_than_cpp-typedefs.h | 5 | ||||
-rw-r--r-- | tests/cxx/iwyu_stricter_than_cpp.cc | 6 |
4 files changed, 12 insertions, 10 deletions
@@ -2667,12 +2667,6 @@ class IwyuBaseAstVisitor : public BaseAstVisitor<Derived> { parent_type = GetTypeOf(decl); } else if (const auto *decl = ast_node->GetParentAs<TypeDecl>()) { - // Elaborated types in type decls are always forward-declarable - // (and usually count as forward declarations themselves). - if (IsElaboratedTypeSpecifier(ast_node)) { - return true; - } - // If we ourselves are a forward-decl -- that is, we're the type // component of a forward-declaration (which would be our parent // AST node) -- then we're forward-declarable by definition. diff --git a/tests/cxx/iwyu_stricter_than_cpp-type_alias.h b/tests/cxx/iwyu_stricter_than_cpp-type_alias.h index 736ee9e..aa60fd8 100644 --- a/tests/cxx/iwyu_stricter_than_cpp-type_alias.h +++ b/tests/cxx/iwyu_stricter_than_cpp-type_alias.h @@ -29,6 +29,9 @@ using DoesNotForwardDeclareProperlyAl = IndirectStructForwardDeclaredInD1; struct DirectStruct1; using IncludesAl = DirectStruct1; +// Essentially the same; should require corresponding header inclusion here. +using IncludesElaboratedAl = struct DirectStruct3; + // Requires the full type because it does not obey rules (1) *or* (2) using DoesNotForwardDeclareAndIncludesAl = DirectStruct2; @@ -76,7 +79,7 @@ tests/cxx/iwyu_stricter_than_cpp-type_alias.h should remove these lines: - template <typename T> struct TplDirectStruct1; // lines XX-XX The full include-list for tests/cxx/iwyu_stricter_than_cpp-type_alias.h: -#include "tests/cxx/iwyu_stricter_than_cpp-d1.h" // for DirectStruct1, DirectStruct2, TplDirectStruct1, TplDirectStruct2 +#include "tests/cxx/iwyu_stricter_than_cpp-d1.h" // for DirectStruct1, DirectStruct2, DirectStruct3, TplDirectStruct1, TplDirectStruct2 #include "tests/cxx/iwyu_stricter_than_cpp-i1.h" // for IndirectStruct1, IndirectStructForwardDeclaredInD1, TplIndirectStruct1, TplIndirectStructForwardDeclaredInD1 struct IndirectStruct2; // lines XX-XX struct IndirectStruct3; // lines XX-XX diff --git a/tests/cxx/iwyu_stricter_than_cpp-typedefs.h b/tests/cxx/iwyu_stricter_than_cpp-typedefs.h index 0421a8e..e51be80 100644 --- a/tests/cxx/iwyu_stricter_than_cpp-typedefs.h +++ b/tests/cxx/iwyu_stricter_than_cpp-typedefs.h @@ -29,6 +29,9 @@ typedef IndirectStructForwardDeclaredInD1 DoesNotForwardDeclareProperly; struct DirectStruct1; typedef DirectStruct1 Includes; +// Essentially the same; should require corresponding header inclusion here. +typedef struct DirectStruct3 IncludesElaborated; + // Requires the full type because it does not obey rules (1) *or* (2) typedef DirectStruct2 DoesNotForwardDeclareAndIncludes; @@ -76,7 +79,7 @@ tests/cxx/iwyu_stricter_than_cpp-typedefs.h should remove these lines: - template <typename T> struct TplDirectStruct1; // lines XX-XX The full include-list for tests/cxx/iwyu_stricter_than_cpp-typedefs.h: -#include "tests/cxx/iwyu_stricter_than_cpp-d1.h" // for DirectStruct1, DirectStruct2, TplDirectStruct1, TplDirectStruct2 +#include "tests/cxx/iwyu_stricter_than_cpp-d1.h" // for DirectStruct1, DirectStruct2, DirectStruct3, TplDirectStruct1, TplDirectStruct2 #include "tests/cxx/iwyu_stricter_than_cpp-i1.h" // for IndirectStruct1, IndirectStructForwardDeclaredInD1, TplIndirectStruct1, TplIndirectStructForwardDeclaredInD1 struct IndirectStruct2; // lines XX-XX struct IndirectStruct3; // lines XX-XX diff --git a/tests/cxx/iwyu_stricter_than_cpp.cc b/tests/cxx/iwyu_stricter_than_cpp.cc index c8e69bb..3a12409 100644 --- a/tests/cxx/iwyu_stricter_than_cpp.cc +++ b/tests/cxx/iwyu_stricter_than_cpp.cc @@ -55,6 +55,7 @@ void TestTypedefs() { DoesNotForwardDeclare dnfd(1); DoesNotForwardDeclareProperly dnfdp(2); Includes i(3); + IncludesElaborated ie(3); DoesNotForwardDeclareAndIncludes dnfdai(4); // IWYU: IndirectStruct2 is...*iwyu_stricter_than_cpp-i2.h DoesEverythingRight dor(5); @@ -101,6 +102,7 @@ void TestTypeAliases() { DoesNotForwardDeclareAl dnfd(1); DoesNotForwardDeclareProperlyAl dnfdp(2); IncludesAl i(3); + IncludesElaboratedAl ie(3); DoesNotForwardDeclareAndIncludesAl dnfdai(4); // IWYU: IndirectStruct2 is...*iwyu_stricter_than_cpp-i2.h DoesEverythingRightAl dor(5); @@ -240,8 +242,8 @@ The full include-list for tests/cxx/iwyu_stricter_than_cpp.cc: #include "tests/cxx/iwyu_stricter_than_cpp-i2.h" // for IndirectStruct2, TplIndirectStruct2 #include "tests/cxx/iwyu_stricter_than_cpp-i3.h" // for IndirectStruct3 #include "tests/cxx/iwyu_stricter_than_cpp-i4.h" // for IndirectStruct4 -#include "tests/cxx/iwyu_stricter_than_cpp-type_alias.h" // for DoesEverythingRightAl, DoesNotForwardDeclareAl, DoesNotForwardDeclareAndIncludesAl, DoesNotForwardDeclareProperlyAl, IncludesAl, IndirectStruct3NonProvidingAl, IndirectStruct4NonProvidingAl, TplDoesEverythingRightAgainAl, TplDoesEverythingRightAl, TplDoesNotForwardDeclareAl, TplDoesNotForwardDeclareAndIncludesAl, TplDoesNotForwardDeclareProperlyAl, TplIncludesAl -#include "tests/cxx/iwyu_stricter_than_cpp-typedefs.h" // for DoesEverythingRight, DoesNotForwardDeclare, DoesNotForwardDeclareAndIncludes, DoesNotForwardDeclareProperly, Includes, IndirectStruct3NonProvidingTypedef, IndirectStruct4NonProvidingTypedef, TplDoesEverythingRight, TplDoesEverythingRightAgain, TplDoesNotForwardDeclare, TplDoesNotForwardDeclareAndIncludes, TplDoesNotForwardDeclareProperly, TplIncludes +#include "tests/cxx/iwyu_stricter_than_cpp-type_alias.h" // for DoesEverythingRightAl, DoesNotForwardDeclareAl, DoesNotForwardDeclareAndIncludesAl, DoesNotForwardDeclareProperlyAl, IncludesAl, IncludesElaboratedAl, IndirectStruct3NonProvidingAl, IndirectStruct4NonProvidingAl, TplDoesEverythingRightAgainAl, TplDoesEverythingRightAl, TplDoesNotForwardDeclareAl, TplDoesNotForwardDeclareAndIncludesAl, TplDoesNotForwardDeclareProperlyAl, TplIncludesAl +#include "tests/cxx/iwyu_stricter_than_cpp-typedefs.h" // for DoesEverythingRight, DoesNotForwardDeclare, DoesNotForwardDeclareAndIncludes, DoesNotForwardDeclareProperly, Includes, IncludesElaborated, IndirectStruct3NonProvidingTypedef, IndirectStruct4NonProvidingTypedef, TplDoesEverythingRight, TplDoesEverythingRightAgain, TplDoesNotForwardDeclare, TplDoesNotForwardDeclareAndIncludes, TplDoesNotForwardDeclareProperly, TplIncludes struct DirectStruct1; struct DirectStruct2; struct IndirectStruct1; |