summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-10-10 14:26:40 +0000
committerEric Fiselier <eric@efcs.ca>2016-10-10 14:26:40 +0000
commit46257d7ee4fb768cae24e781beaa4afbc225be32 (patch)
treec75efb9f9a96a94ea832e352ee3ae6964ab5f448
parent61a39e4b5bf70f40db70d51f71948a66e567c559 (diff)
downloadclang-46257d7ee4fb768cae24e781beaa4afbc225be32.tar.gz
[Sema] Prevent using member declaration diagnostic if the base class is invalid.
Summary: Once a base class has been made invalid (by a static_assert for example) all using-member declarations in the derived classes will result in a "not a base class" diagnostic. This diagnostic is very misleading and should not be emitted. This change is needed to help libc++ produce reasonable diagnostics in `std::optional` and `std::variant`. Reviewers: rsmith, majnemer, aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25430 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283755 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclCXX.cpp12
-rw-r--r--test/SemaCXX/using-decl-templates.cpp9
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 0f7f0ffa75..7eca6c1b61 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -9470,11 +9470,13 @@ bool Sema::CheckUsingDeclQualifier(SourceLocation UsingLoc,
return true;
}
- Diag(SS.getRange().getBegin(),
- diag::err_using_decl_nested_name_specifier_is_not_base_class)
- << SS.getScopeRep()
- << cast<CXXRecordDecl>(CurContext)
- << SS.getRange();
+ if (!cast<CXXRecordDecl>(NamedContext)->isInvalidDecl()) {
+ Diag(SS.getRange().getBegin(),
+ diag::err_using_decl_nested_name_specifier_is_not_base_class)
+ << SS.getScopeRep()
+ << cast<CXXRecordDecl>(CurContext)
+ << SS.getRange();
+ }
return true;
}
diff --git a/test/SemaCXX/using-decl-templates.cpp b/test/SemaCXX/using-decl-templates.cpp
index d766bb3ac6..3b2b8e15c8 100644
--- a/test/SemaCXX/using-decl-templates.cpp
+++ b/test/SemaCXX/using-decl-templates.cpp
@@ -92,3 +92,12 @@ namespace aliastemplateinst {
template struct APtr<int>; // expected-error{{elaborated type refers to a type alias template}}
}
+
+namespace DontDiagnoseInvalidTest {
+template <bool Value> struct Base {
+ static_assert(Value, ""); // expected-error {{static_assert failed}}
+};
+struct Derived : Base<false> { // expected-note {{requested here}}
+ using Base<false>::Base; // OK. Don't diagnose that 'Base' isn't a base class of Derived.
+};
+} // namespace DontDiagnoseInvalidTest