1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions -verify %s
2 void bar(int * param
) {}
6 int *p
= new int[4]; // expected-warning{{'p' is an unsafe pointer used for buffer access}}
8 int tmp
= p
[9]; // expected-note{{used in buffer access here}}
10 q
= r
; // FIXME: we do not fix `q = r` here as the `.data()` fix-it is not generally correct
15 int *p
= new int[4]; // expected-warning{{'p' is an unsafe pointer used for buffer access}} // expected-note{{change type of 'p' to 'std::span' to preserve bounds information, and change 'r' to 'std::span' to propagate bounds information between them}}
18 p
[5] = 4; // expected-note{{used in buffer access here}}
21 void uuc_if_body1(bool flag
) {
23 int *p
= new int[4]; // expected-warning{{'p' is an unsafe pointer used for buffer access}} // expected-note{{change type of 'p' to 'std::span' to preserve bounds information, and change 'r' to 'std::span' to propagate bounds information between them}}
27 p
[5] = 4; // expected-note{{used in buffer access here}}
30 void uuc_if_body2(bool flag
) {
32 int *p
= new int[4]; // expected-warning{{'p' is an unsafe pointer used for buffer access}} // expected-note{{change type of 'p' to 'std::span' to preserve bounds information, and change 'r' to 'std::span' to propagate bounds information between them}}
38 p
[5] = 4; // expected-note{{used in buffer access here}}
41 void uuc_if_body2_ptr_init(bool flag
) {
45 int* p
= r
; // expected-warning{{'p' is an unsafe pointer used for buffer access}} // expected-note{{change type of 'p' to 'std::span' to preserve bounds information, and change 'r' to 'std::span' to propagate bounds information between them}}
46 p
[5] = 4; // expected-note{{used in buffer access here}}
50 void uuc_if_cond_no_unsafe_op() {
58 void uuc_if_cond_no_unsafe_op1() {
67 void uuc_if_cond_unsafe_op() {
69 int *p
= new int[4]; //expected-warning{{'p' is an unsafe pointer used for buffer access}}
71 p
[3] = 2; // expected-note{{used in buffer access here}}
75 void uuc_if_cond_unsafe_op1() {
76 int *r
= new int[7]; // expected-warning{{'r' is an unsafe pointer used for buffer access}}
79 r
[3] = 2; // expected-note{{used in buffer access here}}
83 void uuc_if_cond_unsafe_op2() {
84 int *r
= new int[7]; // expected-warning{{'r' is an unsafe pointer used for buffer access}}
85 int *p
= new int[4]; // expected-warning{{'p' is an unsafe pointer used for buffer access}}
87 r
[3] = 2; // expected-note{{used in buffer access here}}
89 p
[4] = 6; // expected-note{{used in buffer access here}}
93 int *w
= new int[4]; // expected-warning{{'w' is an unsafe pointer used for buffer access}}
96 w
[5] = 0; // expected-note{{used in buffer access here}}