[clang] f8f1e5f - [AST] Fix dependence-bits for CXXDefaultInitExpr.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 20 23:47:22 PDT 2020
Author: Haojian Wu
Date: 2020-09-21T08:47:01+02:00
New Revision: f8f1e5fb39d20985974658fb3d4401a80c0fcccd
URL: https://github.com/llvm/llvm-project/commit/f8f1e5fb39d20985974658fb3d4401a80c0fcccd
DIFF: https://github.com/llvm/llvm-project/commit/f8f1e5fb39d20985974658fb3d4401a80c0fcccd.diff
LOG: [AST] Fix dependence-bits for CXXDefaultInitExpr.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D87382
Added:
Modified:
clang/include/clang/AST/ComputeDependence.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/AST/ExprCXX.cpp
clang/test/SemaCXX/invalid-constructor-init.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ComputeDependence.h b/clang/include/clang/AST/ComputeDependence.h
index ac2daf9eb95a..6af0e4604b63 100644
--- a/clang/include/clang/AST/ComputeDependence.h
+++ b/clang/include/clang/AST/ComputeDependence.h
@@ -70,6 +70,7 @@ class CXXPseudoDestructorExpr;
class OverloadExpr;
class DependentScopeDeclRefExpr;
class CXXConstructExpr;
+class CXXDefaultInitExpr;
class LambdaExpr;
class CXXUnresolvedConstructExpr;
class CXXDependentScopeMemberExpr;
@@ -153,6 +154,7 @@ ExprDependence computeDependence(OverloadExpr *E, bool KnownDependent,
bool KnownContainsUnexpandedParameterPack);
ExprDependence computeDependence(DependentScopeDeclRefExpr *E);
ExprDependence computeDependence(CXXConstructExpr *E);
+ExprDependence computeDependence(CXXDefaultInitExpr *E);
ExprDependence computeDependence(LambdaExpr *E,
bool ContainsUnexpandedParameterPack);
ExprDependence computeDependence(CXXUnresolvedConstructExpr *E);
diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp
index c3a209026662..320025e5fc82 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -694,6 +694,10 @@ ExprDependence clang::computeDependence(CXXConstructExpr *E) {
return D;
}
+ExprDependence clang::computeDependence(CXXDefaultInitExpr *E) {
+ return E->getExpr()->getDependence();
+}
+
ExprDependence clang::computeDependence(LambdaExpr *E,
bool ContainsUnexpandedParameterPack) {
auto D = toExprDependence(E->getType()->getDependence());
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 1fd2b8e3b4e2..fe2de4b8cbce 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -959,7 +959,7 @@ CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx,
CXXDefaultInitExprBits.Loc = Loc;
assert(Field->hasInClassInitializer());
- setDependence(ExprDependence::None);
+ setDependence(computeDependence(this));
}
CXXTemporary *CXXTemporary::Create(const ASTContext &C,
diff --git a/clang/test/SemaCXX/invalid-constructor-init.cpp b/clang/test/SemaCXX/invalid-constructor-init.cpp
index df10afb1d726..3e0c8b59c1bb 100644
--- a/clang/test/SemaCXX/invalid-constructor-init.cpp
+++ b/clang/test/SemaCXX/invalid-constructor-init.cpp
@@ -9,8 +9,7 @@ struct X {
constexpr int Z = X().Y; // expected-error {{constexpr variable 'Z' must be initialized by a constant expression}}
struct X2 {
- int Y = foo(); // expected-error {{use of undeclared identifier 'foo'}} \
- // expected-note {{subexpression not valid in a constant expression}}
+ int Y = foo(); // expected-error {{use of undeclared identifier 'foo'}}
constexpr X2() {} // expected-error {{constexpr constructor never produces a constant expression}}
};
@@ -27,3 +26,9 @@ struct CycleDelegate {
// no bogus "delegation cycle" diagnostic
CycleDelegate(float) : CycleDelegate(1) {}
};
+
+struct X4 {
+ int* p = new int(invalid()); // expected-error {{use of undeclared identifier}}
+};
+// no crash on evaluating the CXXDefaultInitExpr.
+constexpr int* s = X4().p; // expected-error {{must be initialized by}}
More information about the cfe-commits
mailing list