[PATCH] D86765: [clang] Don't emit "no member" diagnostic if the lookup fails on an invalid record decl.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 28 00:47:33 PDT 2020


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added projects: clang, libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
hokein requested review of this revision.

The "no member" diagnostic is likely bogus.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86765

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/access-base-class.cpp
  libcxx/test/libcxx/utilities/memory/util.smartptr/util.smartptr.shared/function_type_default_deleter.fail.cpp


Index: libcxx/test/libcxx/utilities/memory/util.smartptr/util.smartptr.shared/function_type_default_deleter.fail.cpp
===================================================================
--- libcxx/test/libcxx/utilities/memory/util.smartptr/util.smartptr.shared/function_type_default_deleter.fail.cpp
+++ libcxx/test/libcxx/utilities/memory/util.smartptr/util.smartptr.shared/function_type_default_deleter.fail.cpp
@@ -37,8 +37,6 @@
     SPtr<3> s3(nullptr, Deleter{}); // OK
   }
   // expected-error-re at memory:* 2 {{static_assert failed{{.*}} "default_delete cannot be instantiated for function types"}}
-  // FIXME: suppress this bogus diagnostic, see https://reviews.llvm.org/D86685.
-  // expected-error at memory:* 0+ {{no member named 'value' in}}
   {
     SPtr<4> s4(getFn<4>()); // expected-note {{requested here}}
     SPtr<5> s5(getFn<5>(), std::default_delete<FnType<5>>{}); // expected-note {{requested here}}
Index: clang/test/SemaCXX/access-base-class.cpp
===================================================================
--- clang/test/SemaCXX/access-base-class.cpp
+++ clang/test/SemaCXX/access-base-class.cpp
@@ -89,3 +89,29 @@
   };
 }
 
+namespace T8 {
+template <int>
+struct flag {
+  static constexpr bool value = true;
+};
+
+template <class T>
+struct trait : flag<sizeof(T)> {};
+
+template <class T, bool Inferred = trait<T>::value>
+struct a {};
+
+template <class T>
+class b {
+  a<T> x;
+  using U = a<T>;
+};
+
+template <int>
+struct Impossible {
+  static_assert(false, ""); // expected-error {{static_assert failed}}
+};
+
+// verify "no member named 'value'" bogus diagnostic is not emitted.
+trait<b<Impossible<0>>>::value;
+} // namespace T8
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -2580,6 +2580,13 @@
                                      NameInfo, /*TemplateArgs=*/nullptr);
 
   if (R.empty()) {
+    // Don't diagnose problems with invalid record decl, the no_member
+    // diagnostic is likely bogus, e.g. if a base specificer is invalid, the
+    // derived class is invalid, and has no base class attached, lookup of base
+    // class members will fails.
+    if (const auto *CD = dyn_cast<CXXRecordDecl>(DC))
+      if (CD->isInvalidDecl())
+        return ExprError();
     Diag(NameInfo.getLoc(), diag::err_no_member)
       << NameInfo.getName() << DC << SS.getRange();
     return ExprError();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86765.288539.patch
Type: text/x-patch
Size: 2474 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200828/bea028af/attachment-0001.bin>


More information about the cfe-commits mailing list