[PATCH] D9898: MismatchingNewDeleteDetector uses incorrect field, and finds no initializer

Ismail Pazarbasi via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 12:22:45 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL251335: MismatchingNewDeleteDetector uses incorrect field, and finds no initializer (authored by ismailp).

Changed prior to commit:
  http://reviews.llvm.org/D9898?vs=26271&id=38449#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D9898

Files:
  cfe/trunk/lib/Sema/SemaExprCXX.cpp
  cfe/trunk/test/SemaCXX/delete.cpp

Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -2500,8 +2500,10 @@
 MismatchingNewDeleteDetector::MismatchResult
 MismatchingNewDeleteDetector::analyzeInClassInitializer() {
   assert(Field != nullptr && "This should be called only for members");
-  if (const CXXNewExpr *NE =
-          getNewExprFromInitListOrExpr(Field->getInClassInitializer())) {
+  const Expr *InitExpr = Field->getInClassInitializer();
+  if (!InitExpr)
+    return EndOfTU ? NoMismatch : AnalyzeLater;
+  if (const CXXNewExpr *NE = getNewExprFromInitListOrExpr(InitExpr)) {
     if (NE->isArray() != IsArrayForm) {
       NewExprs.push_back(NE);
       return MemberInitMismatches;
Index: cfe/trunk/test/SemaCXX/delete.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/delete.cpp
+++ cfe/trunk/test/SemaCXX/delete.cpp
@@ -120,6 +120,22 @@
   DELETE(d);          // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
 }
 }
+
+namespace MissingInitializer {
+template<typename T>
+struct Base {
+  struct S {
+    const T *p1 = nullptr;
+    const T *p2 = new T[3];
+  };
+};
+
+void null_init(Base<double>::S s) {
+  delete s.p1;
+  delete s.p2;
+}
+}
+
 #ifndef WITH_PCH
 pch_test::X::X()
   : a(new int[1])  // expected-note{{allocated with 'new[]' here}}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9898.38449.patch
Type: text/x-patch
Size: 1483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151026/49769cb4/attachment.bin>


More information about the cfe-commits mailing list