diff options
author | Haojian Wu <hokein.wu@gmail.com> | 2020-10-05 10:35:29 +0200 |
---|---|---|
committer | Haojian Wu <hokein.wu@gmail.com> | 2020-10-05 10:35:29 +0200 |
commit | 3423d5c9da812b0076d1cf14e96ce453e35257b6 (patch) | |
tree | 0977511fea439eeb7737a266d34b512e71ca3d34 | |
parent | a3caf7f6102dc863425f9714b099af58397f0cd2 (diff) | |
download | llvm-3423d5c9da812b0076d1cf14e96ce453e35257b6.zip llvm-3423d5c9da812b0076d1cf14e96ce453e35257b6.tar.gz llvm-3423d5c9da812b0076d1cf14e96ce453e35257b6.tar.bz2 |
[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
-rw-r--r-- | clang/lib/AST/ComputeDependence.cpp | 8 | ||||
-rw-r--r-- | clang/test/Sema/invalid-member.cpp | 8 |
2 files changed, 13 insertions, 3 deletions
diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp index 320025e..f8dfeed 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 9559ead..57ee187 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"); |