[clang] 3423d5c - [AST][RecoveryExpr] Popagate the error-bit from a VarDecl's initializer to DeclRefExpr.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 5 01:41:55 PDT 2020
Author: Haojian Wu
Date: 2020-10-05T10:35:29+02:00
New Revision: 3423d5c9da812b0076d1cf14e96ce453e35257b6
URL: https://github.com/llvm/llvm-project/commit/3423d5c9da812b0076d1cf14e96ce453e35257b6
DIFF: https://github.com/llvm/llvm-project/commit/3423d5c9da812b0076d1cf14e96ce453e35257b6.diff
LOG: [AST][RecoveryExpr] Popagate the error-bit from a VarDecl's initializer to DeclRefExpr.
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, `ABC<DeclRefExpr>` could produce a non-error
and non-dependent type in non-template context, which will lead to
crashes in constexpr evaluation.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D86048
Added:
Modified:
clang/lib/AST/ComputeDependence.cpp
clang/test/Sema/invalid-member.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp
index 320025e5fc82..f8dfeed0962e 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -466,10 +466,12 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
: 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:
diff --git a/clang/test/Sema/invalid-member.cpp b/clang/test/Sema/invalid-member.cpp
index 9559ead082f0..57ee187ccf4d 100644
--- a/clang/test/Sema/invalid-member.cpp
+++ b/clang/test/Sema/invalid-member.cpp
@@ -19,3 +19,11 @@ class Z {
};
// 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}}
+template<int a>
+class ABC {};
+class T {
+ ABC<N> abc;
+};
+static_assert(sizeof(T) == 1, "No valid members");
More information about the cfe-commits
mailing list