Fix crash on value-dependent delete-expressions.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 30 Sep 2019 22:55:27 +0000 (22:55 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 30 Sep 2019 22:55:27 +0000 (22:55 +0000)
We used to miscompute the 'value-dependent' bit, and would crash if we
tried to evaluate a delete expression that should be value-dependent.

llvm-svn: 373272

clang/include/clang/AST/ExprCXX.h
clang/test/SemaCXX/constant-expression-cxx2a.cpp

index 8e13eb5..61e7a91 100644 (file)
@@ -2278,8 +2278,8 @@ public:
   CXXDeleteExpr(QualType Ty, bool GlobalDelete, bool ArrayForm,
                 bool ArrayFormAsWritten, bool UsualArrayDeleteWantsSize,
                 FunctionDecl *OperatorDelete, Expr *Arg, SourceLocation Loc)
-      : Expr(CXXDeleteExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
-             Arg->isInstantiationDependent(),
+      : Expr(CXXDeleteExprClass, Ty, VK_RValue, OK_Ordinary, false,
+             Arg->isValueDependent(), Arg->isInstantiationDependent(),
              Arg->containsUnexpandedParameterPack()),
         OperatorDelete(OperatorDelete), Argument(Arg) {
     CXXDeleteExprBits.GlobalDelete = GlobalDelete;
index 0cf41d8..08fcfdd 100644 (file)
@@ -1056,6 +1056,12 @@ namespace delete_random_things {
   static_assert((delete &(int&)(int&&)0, true)); // expected-error {{}} expected-note {{delete of pointer '&0' that does not point to a heap-allocated object}} expected-note {{temporary created here}}
 }
 
+namespace value_dependent_delete {
+  template<typename T> void f(T *p) {
+    int arr[(delete p, 0)];
+  }
+}
+
 namespace memory_leaks {
   static_assert(*new bool(true)); // expected-error {{}} expected-note {{allocation performed here was not deallocated}}