From 46257d7ee4fb768cae24e781beaa4afbc225be32 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 10 Oct 2016 14:26:40 +0000 Subject: [PATCH] [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 --- lib/Sema/SemaDeclCXX.cpp | 12 +++++++----- test/SemaCXX/using-decl-templates.cpp | 9 +++++++++ 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(CurContext) - << SS.getRange(); + if (!cast(NamedContext)->isInvalidDecl()) { + Diag(SS.getRange().getBegin(), + diag::err_using_decl_nested_name_specifier_is_not_base_class) + << SS.getScopeRep() + << cast(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; // expected-error{{elaborated type refers to a type alias template}} } + +namespace DontDiagnoseInvalidTest { +template struct Base { + static_assert(Value, ""); // expected-error {{static_assert failed}} +}; +struct Derived : Base { // expected-note {{requested here}} + using Base::Base; // OK. Don't diagnose that 'Base' isn't a base class of Derived. +}; +} // namespace DontDiagnoseInvalidTest -- 2.40.0