diff options
author | Bolshakov <bolsh.andrey@yandex.ru> | 2021-09-20 21:43:33 +0300 |
---|---|---|
committer | Kim Gräsman <kim.grasman@gmail.com> | 2021-10-03 16:29:52 +0200 |
commit | 532dacdf31ee59b8a52e5f623346dd280f42378d (patch) | |
tree | c66583e6c75fce6f5ec8d9e2193d45e070bc62f1 | |
parent | 75226c1ce8f26395c1c5bacf922728a32d7ea011 (diff) |
Don't require aliased type method callability
Don't require aliased type method callability if explicitly forward-
declared according to the IWYU forward declaration policy
-rw-r--r-- | iwyu.cc | 5 | ||||
-rw-r--r-- | tests/cxx/no_forced_alias_callability-d1.h | 14 | ||||
-rw-r--r-- | tests/cxx/no_forced_alias_callability-d2.h | 18 | ||||
-rw-r--r-- | tests/cxx/no_forced_alias_callability.cc | 29 |
4 files changed, 65 insertions, 1 deletions
@@ -3944,7 +3944,10 @@ class IwyuAstConsumer // This is called from Traverse*() because Visit*() // can't call HandleFunctionCall(). bool HandleAliasedClassMethods(TypedefNameDecl* decl) { - if (CanIgnoreCurrentASTNode()) return true; + if (CanIgnoreCurrentASTNode()) + return true; + if (current_ast_node()->in_forward_declare_context()) + return true; const Type* underlying_type = decl->getUnderlyingType().getTypePtr(); const Decl* underlying_decl = TypeToDeclAsWritten(underlying_type); diff --git a/tests/cxx/no_forced_alias_callability-d1.h b/tests/cxx/no_forced_alias_callability-d1.h new file mode 100644 index 0000000..895a73f --- /dev/null +++ b/tests/cxx/no_forced_alias_callability-d1.h @@ -0,0 +1,14 @@ +//===--- no_forced_alias_callability-d1.h - test input file for iwyu ------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +struct ReturnType; + +struct Aliased { + ReturnType doSomething(); +}; diff --git a/tests/cxx/no_forced_alias_callability-d2.h b/tests/cxx/no_forced_alias_callability-d2.h new file mode 100644 index 0000000..7be9a1b --- /dev/null +++ b/tests/cxx/no_forced_alias_callability-d2.h @@ -0,0 +1,18 @@ +//===--- no_forced_alias_callability-d2.h - test input file for iwyu ------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +struct Aliased; + +typedef Aliased Alias; + +/**** IWYU_SUMMARY + +(tests/cxx/no_forced_alias_callability-d2.h has correct #includes/fwd-decls) + +***** IWYU_SUMMARY */ diff --git a/tests/cxx/no_forced_alias_callability.cc b/tests/cxx/no_forced_alias_callability.cc new file mode 100644 index 0000000..6d4ce0a --- /dev/null +++ b/tests/cxx/no_forced_alias_callability.cc @@ -0,0 +1,29 @@ +//===--- no_forced_alias_callability.cc - test input file for iwyu --------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// IWYU_ARGS: -Xiwyu --check_also="tests/cxx/no_forced_alias_callability-d2.h" \ +// -I . + +// Tests that IWYU doesn't require inclusion of an aliased class header +// (...-d1.h) into a header with the alias to provide callability of methods +// of the aliased class if the aliased class is explicitly made forward declared +// in accordance with the IWYU policy + +#include "tests/cxx/no_forced_alias_callability-d1.h" +#include "tests/cxx/no_forced_alias_callability-d2.h" + +int main() { + Alias a; +} + +/**** IWYU_SUMMARY + +(tests/cxx/no_forced_alias_callability.cc has correct #includes/fwd-decls) + +***** IWYU_SUMMARY */ |