[PATCH] D86048: [AST][RecoveryExpr] Popagate the error-bit from a VarDecl's initializer to DeclRefExpr.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 17 00:28:45 PDT 2020


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.
hokein requested review of this revision.

The error-bit was missing, if a DeclRefExpr (which refers to a VarDecl
with a contains-errors initializer).

It could cause different violations in clang -- the DeclRefExpr is value-dependent,
but not contains-errors, `decltype(DeclRefExpr)` could produce a non-error
dependent type in non-template context.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86048

Files:
  clang/lib/AST/ComputeDependence.cpp
  clang/test/Sema/invalid-member.cpp
  clang/test/SemaCXX/invalid-template-base-specifier.cpp


Index: clang/test/SemaCXX/invalid-template-base-specifier.cpp
===================================================================
--- clang/test/SemaCXX/invalid-template-base-specifier.cpp
+++ clang/test/SemaCXX/invalid-template-base-specifier.cpp
@@ -26,3 +26,10 @@
 };
 
 void test3() { Crash3<int>(); } // expected-note {{in instantiation of template class}}
+
+constexpr int N = undef; // expected-error {{use of undeclared identifier}}
+
+class Crash4 : decltype(N) {
+};
+
+static_assert(sizeof(Crash4) == 1, "");
Index: clang/test/Sema/invalid-member.cpp
===================================================================
--- clang/test/Sema/invalid-member.cpp
+++ clang/test/Sema/invalid-member.cpp
@@ -19,3 +19,10 @@
 };
 // Should be able to evaluate sizeof without crashing.
 static_assert(sizeof(Z) == 1, "No valid members");
+
+constexpr int N = undef; // expected-error {{use of undeclared identifier}}
+
+class T {
+  decltype(N) member;
+};
+static_assert(sizeof(T) == 1, "No valid members");
Index: clang/lib/AST/ComputeDependence.cpp
===================================================================
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -466,11 +466,13 @@
              : Var->getType()->isIntegralOrEnumerationType()) &&
         (Var->getType().isConstQualified() ||
          Var->getType()->isReferenceType())) {
-      if (const Expr *Init = Var->getAnyInitializer())
-        if (Init->isValueDependent()) {
+      if (const Expr *Init = Var->getAnyInitializer()) {
+        if (Init->isValueDependent())
           Deps |= ExprDependence::ValueInstantiation;
+        if (Init->containsErrors()) {
+          Deps |= ExprDependence::Error;
         }
-    }
+      }
 
     // (VD) - FIXME: Missing from the standard:
     //      -  a member function or a static data member of the current


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86048.285924.patch
Type: text/x-patch
Size: 1865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200817/ba1331e6/attachment.bin>


More information about the cfe-commits mailing list