r283755 - [Sema] Prevent using member declaration diagnostic if the base class is invalid.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 10 07:26:40 PDT 2016
Author: ericwf
Date: Mon Oct 10 09:26:40 2016
New Revision: 283755
URL: http://llvm.org/viewvc/llvm-project?rev=283755&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/using-decl-templates.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=283755&r1=283754&r2=283755&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Oct 10 09:26:40 2016
@@ -9470,11 +9470,13 @@ bool Sema::CheckUsingDeclQualifier(Sourc
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;
}
Modified: cfe/trunk/test/SemaCXX/using-decl-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/using-decl-templates.cpp?rev=283755&r1=283754&r2=283755&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/using-decl-templates.cpp (original)
+++ cfe/trunk/test/SemaCXX/using-decl-templates.cpp Mon Oct 10 09:26:40 2016
@@ -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
More information about the cfe-commits
mailing list