summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Grasman <kim.grasman@gmail.com>2017-04-30 23:26:04 +0200
committerKim Gräsman <kim.grasman@gmail.com>2017-05-08 07:02:06 +0200
commit301f8ccc426c7ca1d2216d5bf6ffc3a284c49868 (patch)
tree50d6387a9fed4181d6d6092007372e1a528a98df
parentc452de6bc9965bf35fd16767e8291afb14eb8a9c (diff)
Accept methods hiding using declarations
When a method in a derived class hides a name introduced by a using-declaration, Clang discards the using shadow declarations for the hidden name. We used to have an assertion that every using-declaration must have a shadow declaration. This patch removes it, to placate the above. Fixes issue #420.
-rw-r--r--iwyu_output.cc17
-rw-r--r--tests/cxx/using_unused-baseclass.h13
-rw-r--r--tests/cxx/using_unused.cc11
3 files changed, 33 insertions, 8 deletions
diff --git a/iwyu_output.cc b/iwyu_output.cc
index f56499e..9258dfe 100644
--- a/iwyu_output.cc
+++ b/iwyu_output.cc
@@ -1944,15 +1944,16 @@ void IwyuFileInfo::ResolvePendingAnalysis() {
for (map<const UsingDecl*, bool>::value_type using_decl_status
: using_decl_referenced_) {
if (!using_decl_status.second) {
+ // There are valid cases where there is no shadow decl, e.g. if a derived
+ // class has a using declaration for a member, but also hides it.
+ // Only report the target if we have a shadow decl.
const UsingDecl* using_decl = using_decl_status.first;
- // It should not be possible to get here with a using decl without any
- // shadow decls because doing so would imply that the input code we're
- // analyzing code doesn't compile.
- CHECK_(using_decl->shadow_size() > 0);
- ReportForwardDeclareUse(using_decl->getUsingLoc(),
- using_decl->shadow_begin()->getTargetDecl(),
- /* in_cxx_method_body */ false,
- "(for un-referenced using)");
+ if (using_decl->shadow_size() > 0) {
+ ReportForwardDeclareUse(using_decl->getUsingLoc(),
+ using_decl->shadow_begin()->getTargetDecl(),
+ /* in_cxx_method_body */ false,
+ "(for un-referenced using)");
+ }
}
}
}
diff --git a/tests/cxx/using_unused-baseclass.h b/tests/cxx/using_unused-baseclass.h
new file mode 100644
index 0000000..88c7266
--- /dev/null
+++ b/tests/cxx/using_unused-baseclass.h
@@ -0,0 +1,13 @@
+//===--- using_unused-baseclass.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.
+//
+//===----------------------------------------------------------------------===//
+
+class Base {
+ public:
+ void Method();
+};
diff --git a/tests/cxx/using_unused.cc b/tests/cxx/using_unused.cc
index 941f6c8..c72f419 100644
--- a/tests/cxx/using_unused.cc
+++ b/tests/cxx/using_unused.cc
@@ -12,8 +12,19 @@
// it's not actually used.
#include "using_unused-declare.h"
+#include "using_unused-baseclass.h"
+
using ns::symbol;
+class Hiding : public Base {
+ // Introduce a using shadow decl which is subsequently discarded when this
+ // class hides the using-decl with its own declaration.
+ // This used to trigger an assertion failure.
+ using Base::Method;
+
+ void Method();
+};
+
/**** IWYU_SUMMARY
(tests/cxx/using_unused.cc has correct #includes/fwd-decls)