[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / warn-unsafe-buffer-usage-multi-decl-fixits-test.cpp
blob2509c614d989c9e4b6c90b8283c83c7fa5015c80
1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits -fsafe-buffer-usage-suggestions %s 2>&1 | FileCheck %s
3 void foo1a() {
4 int *r = new int[7];
5 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
6 int *p = new int[4];
7 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
8 p = r;
9 int tmp = p[9];
10 int *q;
11 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
12 q = r; // FIXME: we do not fix `q = r` here as the `.data()` fix-it is not generally correct
15 void foo1b() {
16 int *r = new int[7];
17 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
18 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
19 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 7}"
20 int *p = new int[4];
21 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
22 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
23 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 4}"
24 p = r;
25 int tmp = p[9];
26 int *q = new int[4];
27 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
28 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
29 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 4}"
30 q = r;
31 tmp = q[9];
34 void foo1c() {
35 int *r = new int[7];
36 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
37 int *p = new int[4];
38 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
39 p = r; // FIXME: we do not fix `p = r` here as the `.data()` fix-it is not generally correct
40 int tmp = r[9];
41 int *q;
42 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
43 q = r;
44 tmp = q[9];
47 void foo2a() {
48 int *r = new int[7];
49 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
50 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
51 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 7}"
52 int *p = new int[5];
53 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
54 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
55 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 5}"
56 int *q = new int[4];
57 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
58 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
59 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 4}"
60 p = q;
61 int tmp = p[8];
62 q = r;
65 void foo2b() {
66 int *r = new int[7];
67 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
68 int *p = new int[5];
69 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
70 int *q = new int[4];
71 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
72 p = q; // FIXME: we do not fix `p = q` here as the `.data()` fix-it is not generally correct
73 int tmp = q[8];
74 q = r;
77 void foo2c() {
78 int *r = new int[7];
79 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
80 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
81 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 7}"
82 int *p = new int[5];
83 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
84 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
85 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 5}"
86 int *q = new int[4];
87 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
88 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
89 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 4}"
90 p = q;
91 int tmp = p[8];
92 q = r;
93 tmp = q[8];
96 void foo3a() {
97 int *r = new int[7];
98 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
99 int *p = new int[5];
100 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
101 int *q = new int[4];
102 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
103 q = p; // FIXME: we do not fix `q = p` here as the `.data()` fix-it is not generally correct
104 int tmp = p[8];
105 q = r;
108 void foo3b() {
109 int *r = new int[10];
110 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
111 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
112 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
113 int *p = new int[10];
114 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
115 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
116 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
117 int *q = new int[10];
118 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
119 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
120 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
121 q = p;
122 int tmp = q[8];
123 q = r;