[PATCH] D25430: [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 02:33:22 PDT 2016


EricWF created this revision.
EricWF added reviewers: rsmith, majnemer, aaron.ballman.
EricWF added a subscriber: cfe-commits.

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`.


https://reviews.llvm.org/D25430

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/using-decl-templates.cpp


Index: test/SemaCXX/using-decl-templates.cpp
===================================================================
--- test/SemaCXX/using-decl-templates.cpp
+++ test/SemaCXX/using-decl-templates.cpp
@@ -92,3 +92,17 @@
 
   template struct APtr<int>; // expected-error{{elaborated type refers to a type alias template}}
 }
+
+namespace DontDiagnoseInvalidTest {
+template <class> struct False { enum { value = 0 }; };
+template <class T> struct Base {
+  static_assert(False<T>::value, ""); // expected-error {{static_assert failed}}
+  T value;
+};
+template <class T>
+struct Derived : Base<T> { // expected-note {{requested here}}
+  using Base<T>::Base; // OK. Don't diagnose that 'Base' isn't a base class of Derived.
+};
+template struct Derived<int>; // expected-note {{requested here}}
+
+} // namespace DontDiagnoseInvalidTest
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -9462,11 +9462,13 @@
         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;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25430.74110.patch
Type: text/x-patch
Size: 1586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161010/4e927dc6/attachment.bin>


More information about the cfe-commits mailing list