]> granicus.if.org Git - clang/commitdiff
[analyzer] Remove bogus assert: in C++11, 'new' can do list-initialization.
authorJordan Rose <jordan_rose@apple.com>
Wed, 10 Jul 2013 19:14:10 +0000 (19:14 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 10 Jul 2013 19:14:10 +0000 (19:14 +0000)
Previously, we asserted that whenever 'new' did not include a constructor
call, the type must be a non-record type. In C++11, however, uniform
initialization syntax (braces) allow 'new' to construct records with
list-initialization: "new Point{1, 2}".

Removing this assertion should be perfectly safe; the code here matches
what VisitDeclStmt does for regions allocated on the stack.

<rdar://problem/14403437>

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

lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
test/Analysis/new.cpp

index 3f16c62492263d33f0c24f52c8c239bbf1df0762..1342e4149f6370ebd17f5e53fd26c2be02650849 100644 (file)
@@ -431,8 +431,6 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
     if (!isa<CXXConstructExpr>(Init)) {
       assert(Bldr.getResults().size() == 1);
       Bldr.takeNodes(NewN);
-
-      assert(!CNE->getType()->getPointeeCXXRecordDecl());
       evalBind(Dst, CNE, NewN, Result, State->getSVal(Init, LCtx),
                /*FirstInit=*/IsStandardGlobalOpNewFunction);
     }
index 8d3eee9baa6a49940ae523979a3b75bbfc320537..27cbb0816b2fa5aede9faf0548a26a1295e0074d 100644 (file)
@@ -170,6 +170,16 @@ void testUsingThisAfterDelete() {
   c->f(0); // no-warning
 }
 
+void testAggregateNew() {
+  struct Point { int x, y; };
+  new Point{1, 2}; // no crash
+
+  Point p;
+  new (&p) Point{1, 2}; // no crash
+  clang_analyzer_eval(p.x == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(p.y == 2); // expected-warning{{TRUE}}
+}
+
 //--------------------------------
 // Incorrectly-modelled behavior
 //--------------------------------