diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -4316,7 +4316,8 @@ if (auto *RD = T->getAsCXXRecordDecl()) { if (RD->isUnion()) return APValue((const FieldDecl*)nullptr); - + if (!RD->hasDefinition()) + return APValue(); APValue Struct(APValue::UninitStruct(), RD->getNumBases(), std::distance(RD->field_begin(), RD->field_end())); diff --git a/clang/test/SemaCXX/constant-expression-cxx2a.cpp b/clang/test/SemaCXX/constant-expression-cxx2a.cpp --- a/clang/test/SemaCXX/constant-expression-cxx2a.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx2a.cpp @@ -1401,3 +1401,15 @@ // decreasing address static_assert(f(6) == 543210); } + +namespace NoCrash { +struct ForwardDecl; // expected-note {{forward declaration of}} +struct Foo { // expected-note 2{{candidate constructor}} + ForwardDecl f; // expected-error {{field has incomplete type}} +}; + +constexpr Foo getFoo() { + Foo e = 123; // expected-error {{no viable conversion from 'int' to 'NoCrash::Foo'}} + return e; +} +}