r373173 - Don't crash if a variable with a constexpr destructor has a

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 29 13:30:13 PDT 2019


Author: rsmith
Date: Sun Sep 29 13:30:13 2019
New Revision: 373173

URL: http://llvm.org/viewvc/llvm-project?rev=373173&view=rev
Log:
Don't crash if a variable with a constexpr destructor has a
value-dependent initializer.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=373173&r1=373172&r2=373173&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Sep 29 13:30:13 2019
@@ -13401,7 +13401,8 @@ void Sema::FinalizeVarWithDestructor(Var
 
   // 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(),

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp?rev=373173&r1=373172&r2=373173&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp Sun Sep 29 13:30:13 2019
@@ -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();
+  }
+}




More information about the cfe-commits mailing list