1 // RUN: %clang_analyze_cc1 %s -analyzer-checker=core.uninitialized.NewArraySize -analyzer-output=text -verify
3 #include "Inputs/system-header-simulator-cxx.h"
5 void checkUndefinedElmenetCountValue() {
7 // expected-note@-1{{'n' declared without an initial value}}
9 int *arr
= new int[n
]; // expected-warning{{Element count in new[] is a garbage value}}
10 // expected-note@-1{{Element count in new[] is a garbage value}}
13 void checkUndefinedElmenetCountMultiDimensionalValue() {
15 // expected-note@-1{{'n' declared without an initial value}}
17 auto *arr
= new int[n
][5]; // expected-warning{{Element count in new[] is a garbage value}}
18 // expected-note@-1{{Element count in new[] is a garbage value}}
21 void checkUndefinedElmenetCountReference() {
23 // expected-note@-1{{'n' declared without an initial value}}
26 // expected-note@-1{{'ref' initialized here}}
28 int *arr
= new int[ref
]; // expected-warning{{Element count in new[] is a garbage value}}
29 // expected-note@-1{{Element count in new[] is a garbage value}}
32 void checkUndefinedElmenetCountMultiDimensionalReference() {
34 // expected-note@-1{{'n' declared without an initial value}}
37 // expected-note@-1{{'ref' initialized here}}
39 auto *arr
= new int[ref
][5]; // expected-warning{{Element count in new[] is a garbage value}}
40 // expected-note@-1{{Element count in new[] is a garbage value}}
49 void checkUndefinedElmenetCountFunction() {
50 int *arr
= new int[foo()]; // expected-warning{{Element count in new[] is a garbage value}}
51 // expected-note@-1{{Element count in new[] is a garbage value}}
54 void checkUndefinedElmenetCountMultiDimensionalFunction() {
55 auto *arr
= new int[foo()][5]; // expected-warning{{Element count in new[] is a garbage value}}
56 // expected-note@-1{{Element count in new[] is a garbage value}}
61 void checkUndefinedPlacementElementCount() {
63 // expected-note@-1{{'n' declared without an initial value}}
65 void *buffer
= malloc(sizeof(std::string
) * 10);
67 ::new (buffer
) std::string
[n
]; // expected-warning{{Element count in new[] is a garbage value}}
68 // expected-note@-1{{Element count in new[] is a garbage value}}