[llvm-branch-commits] [cfe-branch] r252290 - Merging r251335:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 6 03:38:49 PST 2015


Author: tstellar
Date: Fri Nov  6 05:38:48 2015
New Revision: 252290

URL: http://llvm.org/viewvc/llvm-project?rev=252290&view=rev
Log:
Merging r251335:

------------------------------------------------------------------------
r251335 | ismail.pazarbasi | 2015-10-26 15:20:24 -0400 (Mon, 26 Oct 2015) | 13 lines

MismatchingNewDeleteDetector uses incorrect field, and finds no initializer

Summary:
In `MismatchingNewDeleteDetector::analyzeInClassInitializer`, if
`Field`'s initializer expression is null, lookup the field in
implicit instantiation, and use found field's the initializer.

Reviewers: rsmith, rtrieu

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D9898

------------------------------------------------------------------------

Modified:
    cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp
    cfe/branches/release_37/test/SemaCXX/delete.cpp

Modified: cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp?rev=252290&r1=252289&r2=252290&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp Fri Nov  6 05:38:48 2015
@@ -2485,8 +2485,10 @@ bool MismatchingNewDeleteDetector::hasMa
 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;

Modified: cfe/branches/release_37/test/SemaCXX/delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/test/SemaCXX/delete.cpp?rev=252290&r1=252289&r2=252290&view=diff
==============================================================================
--- cfe/branches/release_37/test/SemaCXX/delete.cpp (original)
+++ cfe/branches/release_37/test/SemaCXX/delete.cpp Fri Nov  6 05:38:48 2015
@@ -120,6 +120,22 @@ void f() {
   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}}




More information about the llvm-branch-commits mailing list