diff --git a/clang/include/clang/AST/ComputeDependence.h b/clang/include/clang/AST/ComputeDependence.h --- a/clang/include/clang/AST/ComputeDependence.h +++ b/clang/include/clang/AST/ComputeDependence.h @@ -70,6 +70,7 @@ class OverloadExpr; class DependentScopeDeclRefExpr; class CXXConstructExpr; +class CXXDefaultInitExpr; class LambdaExpr; class CXXUnresolvedConstructExpr; class CXXDependentScopeMemberExpr; @@ -153,6 +154,7 @@ 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 --- a/clang/lib/AST/ComputeDependence.cpp +++ b/clang/lib/AST/ComputeDependence.cpp @@ -694,6 +694,10 @@ 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 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -959,7 +959,7 @@ 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 --- a/clang/test/SemaCXX/invalid-constructor-init.cpp +++ b/clang/test/SemaCXX/invalid-constructor-init.cpp @@ -9,8 +9,7 @@ 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 @@ // 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}}