Skip to content

Commit

Permalink
Don't crash if a variable with a constexpr destructor has a
Browse files Browse the repository at this point in the history
value-dependent initializer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373173 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
zygoloid committed Sep 29, 2019
1 parent 868a5a7 commit b3dd071
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13401,7 +13401,8 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {

// If the destructor is constexpr, check whether the variable has constant
// destruction now.
if (Destructor->isConstexpr() && VD->evaluateValue()) {
if (Destructor->isConstexpr() && VD->getInit() &&
!VD->getInit()->isValueDependent() && VD->evaluateValue()) {
SmallVector<PartialDiagnosticAt, 8> Notes;
if (!VD->evaluateDestruction(Notes) && VD->isConstexpr()) {
Diag(VD->getLocation(),
Expand Down
9 changes: 9 additions & 0 deletions test/SemaCXX/constant-expression-cxx2a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,3 +1269,12 @@ namespace temp_dtor {
// FIXME: We could in prinicple accept this.
constexpr const A &c = A{false}; // expected-error {{constant}} expected-note {{non-trivial destruction of lifetime-extended temporary}}
}

namespace value_dependent_init {
struct A {
constexpr ~A() {}
};
template<typename T> void f() {
A a = T();
}
}

0 comments on commit b3dd071

Please sign in to comment.