Procházet zdrojové kódy

Don't crash if a variable with a constexpr destructor has a
value-dependent initializer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373173 91177308-0d34-0410-b5e6-96231b3b80d8

Richard Smith před 5 roky
rodič
revize
b3dd07106f

+ 2 - 1
lib/Sema/SemaDeclCXX.cpp

@@ -13401,7 +13401,8 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
 
 
   // If the destructor is constexpr, check whether the variable has constant
   // If the destructor is constexpr, check whether the variable has constant
   // destruction now.
   // destruction now.
-  if (Destructor->isConstexpr() && VD->evaluateValue()) {
+  if (Destructor->isConstexpr() && VD->getInit() &&
+      !VD->getInit()->isValueDependent() && VD->evaluateValue()) {
     SmallVector<PartialDiagnosticAt, 8> Notes;
     SmallVector<PartialDiagnosticAt, 8> Notes;
     if (!VD->evaluateDestruction(Notes) && VD->isConstexpr()) {
     if (!VD->evaluateDestruction(Notes) && VD->isConstexpr()) {
       Diag(VD->getLocation(),
       Diag(VD->getLocation(),

+ 9 - 0
test/SemaCXX/constant-expression-cxx2a.cpp

@@ -1269,3 +1269,12 @@ namespace temp_dtor {
   // FIXME: We could in prinicple accept this.
   // 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}}
   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();
+  }
+}