diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -1456,6 +1456,13 @@ // TODO: Handle other cases. For now, fail to find construction contexts. break; } + case Stmt::ParenExprClass: { + // If expression is placed into parenthesis we should propagate the parent + // construction context to subexpressions. + auto *PE = cast(Child); + findConstructionContexts(Layer, PE->getSubExpr()); + break; + } default: break; } diff --git a/clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist b/clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist --- a/clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist +++ b/clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist @@ -12,7 +12,7 @@ kindevent location - line24 + line19 col3 file0 @@ -20,12 +20,12 @@ - line24 + line19 col3 file0 - line24 + line19 col10 file0 @@ -45,12 +45,12 @@ start - line17 + line12 col1 file0 - line17 + line12 col4 file0 @@ -58,12 +58,12 @@ end - line18 + line13 col3 file0 - line18 + line13 col5 file0 @@ -75,7 +75,7 @@ kindevent location - line18 + line13 col12 file0 @@ -83,12 +83,12 @@ - line18 + line13 col12 file0 - line18 + line13 col18 file0 @@ -108,12 +108,12 @@ start - line18 + line13 col3 file0 - line18 + line13 col5 file0 @@ -121,12 +121,12 @@ end - line20 + line15 col3 file0 - line20 + line15 col4 file0 @@ -142,12 +142,12 @@ start - line20 + line15 col3 file0 - line20 + line15 col4 file0 @@ -155,12 +155,12 @@ end - line21 + line16 col5 file0 - line21 + line16 col10 file0 @@ -172,7 +172,7 @@ kindevent location - line21 + line16 col5 file0 @@ -180,12 +180,12 @@ - line21 + line16 col5 file0 - line21 + line16 col12 file0 @@ -205,12 +205,12 @@ start - line21 + line16 col5 file0 - line21 + line16 col10 file0 @@ -218,12 +218,12 @@ end - line24 + line19 col3 file0 - line24 + line19 col8 file0 @@ -243,7 +243,7 @@ issue_hash_function_offset7 location - line24 + line19 col3 file0 @@ -251,11 +251,11 @@ 0 - 17 - 18 - 20 - 21 - 24 + 12 + 13 + 15 + 16 + 19 @@ -266,7 +266,7 @@ kindevent location - line35 + line30 col2 file0 @@ -274,12 +274,12 @@ - line35 + line30 col2 file0 - line35 + line30 col12 file0 @@ -295,7 +295,7 @@ kindevent location - line29 + line24 col2 file0 @@ -313,12 +313,12 @@ start - line29 + line24 col2 file0 - line29 + line24 col5 file0 @@ -326,12 +326,12 @@ end - line30 + line25 col3 file0 - line30 + line25 col8 file0 @@ -343,7 +343,7 @@ kindevent location - line30 + line25 col3 file0 @@ -351,12 +351,12 @@ - line30 + line25 col3 file0 - line30 + line25 col13 file0 @@ -372,7 +372,7 @@ kindevent location - line35 + line30 col2 file0 @@ -380,12 +380,12 @@ - line35 + line30 col2 file0 - line35 + line30 col12 file0 @@ -405,12 +405,12 @@ start - line35 + line30 col2 file0 - line35 + line30 col4 file0 @@ -418,12 +418,12 @@ end - line37 + line32 col2 file0 - line37 + line32 col7 file0 @@ -435,7 +435,7 @@ kindevent location - line37 + line32 col2 file0 @@ -443,12 +443,12 @@ - line37 + line32 col2 file0 - line37 + line32 col11 file0 @@ -472,7 +472,7 @@ issue_hash_function_offset3 location - line37 + line32 col2 file0 @@ -480,11 +480,11 @@ 0 + 24 + 25 29 30 - 34 - 35 - 37 + 32 diff --git a/clang/test/Analysis/NewDelete-checker-test.cpp b/clang/test/Analysis/NewDelete-checker-test.cpp --- a/clang/test/Analysis/NewDelete-checker-test.cpp +++ b/clang/test/Analysis/NewDelete-checker-test.cpp @@ -9,20 +9,23 @@ // RUN: -analyzer-checker=cplusplus.NewDelete \ // RUN: -analyzer-checker=cplusplus.NewDeleteLeaks // -// RUN: %clang_analyze_cc1 -std=c++11 -fblocks %s \ +// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \ +// RUN: -verify=expected,leak \ +// RUN: -analyzer-checker=core \ +// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks +// +// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \ // RUN: -verify=expected,newdelete \ // RUN: -analyzer-checker=core \ -// RUN: -analyzer-checker=cplusplus.NewDelete \ -// RUN: -analyzer-config c++-allocator-inlining=true +// RUN: -analyzer-checker=cplusplus.NewDelete // -// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \ +// RUN: %clang_analyze_cc1 -DLEAKS -std=c++17 -fblocks %s \ // RUN: -verify=expected,newdelete,leak \ // RUN: -analyzer-checker=core \ // RUN: -analyzer-checker=cplusplus.NewDelete \ -// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks \ -// RUN: -analyzer-config c++-allocator-inlining=true +// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks // -// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \ +// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \ // RUN: -verify=expected,leak \ // RUN: -analyzer-checker=core \ // RUN: -analyzer-checker=cplusplus.NewDeleteLeaks @@ -288,7 +291,7 @@ explicit shared_ptr(T *p) : p(p), control(new control_block) { control->retain(); } - shared_ptr(shared_ptr &other) : p(other.p), control(other.control) { + shared_ptr(const shared_ptr &other) : p(other.p), control(other.control) { if (control) control->retain(); } @@ -314,11 +317,26 @@ } }; + template + shared_ptr make_shared(Args &&...args) { + return shared_ptr(new T(static_cast(args)...)); + } + void testSingle() { shared_ptr a(new int); *a = 1; } + void testMake() { + shared_ptr a = make_shared(); + *a = 1; + } + + void testMakeInParens() { + shared_ptr a = (make_shared()); // no warn + *a = 1; + } + void testDouble() { shared_ptr a(new int); shared_ptr b = a; diff --git a/clang/test/Analysis/NewDelete-path-notes.cpp b/clang/test/Analysis/NewDelete-path-notes.cpp --- a/clang/test/Analysis/NewDelete-path-notes.cpp +++ b/clang/test/Analysis/NewDelete-path-notes.cpp @@ -4,11 +4,6 @@ // RUN: -analyzer-output=text -verify %s // RUN: %clang_analyze_cc1 \ // RUN: -analyzer-checker=cplusplus.NewDelete,unix.Malloc \ -// RUN: -analyzer-config c++-allocator-inlining=true \ -// RUN: -analyzer-config add-pop-up-notes=false \ -// RUN: -analyzer-output=text -verify %s -// RUN: %clang_analyze_cc1 \ -// RUN: -analyzer-checker=cplusplus.NewDelete,unix.Malloc \ // RUN: -analyzer-config add-pop-up-notes=false \ // RUN: -analyzer-output=plist %s -o %t.plist // RUN: %normalize_plist <%t.plist | diff -ub \ diff --git a/clang/test/Analysis/NewDeleteLeaks-PR19102.cpp b/clang/test/Analysis/NewDeleteLeaks-PR19102.cpp --- a/clang/test/Analysis/NewDeleteLeaks-PR19102.cpp +++ b/clang/test/Analysis/NewDeleteLeaks-PR19102.cpp @@ -1,5 +1,4 @@ // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -verify %s -// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -analyzer-config c++-allocator-inlining=true -verify %s class A0 {};