Skip to content

Commit fd791cc

Browse files
committed
[-Wunsafe-buffer-usage][NFC] Add testcases
1 parent b6688fb commit fd791cc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-array.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ void comments_in_declaration(unsigned idx) {
2222
buffer_w[idx] = 0;
2323
}
2424

25+
void initializer(unsigned idx) {
26+
int buffer[3] = {0};
27+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:16}:"std::array<int, 3> buffer"
28+
29+
int buffer2[3] = {0, 1, 2};
30+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:17}:"std::array<int, 3> buffer2"
31+
32+
buffer[idx] = 0;
33+
buffer2[idx] = 0;
34+
}
35+
2536
void auto_size(unsigned idx) {
2637
int buffer[] = {0, 1, 2};
2738
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
@@ -66,7 +77,15 @@ void local_array_const_ptr(unsigned idx, int*& a) {
6677
// FIXME: implement support
6778

6879
a = buffer[idx];
80+
}
6981

82+
void local_array_const_ptr_via_typedef(unsigned idx, int*& a) {
83+
typedef int * const my_const_ptr;
84+
my_const_ptr buffer[10] = {a};
85+
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
86+
// FIXME: implement support
87+
88+
a = buffer[idx];
7089
}
7190

7291
void local_array_const_ptr_to_const(unsigned idx, const int*& a) {

0 commit comments

Comments
 (0)