Debian Codegraph @

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

raw
1 // RUN: %clang_cc1 -std=c++20 -Wno-everything -Wunsafe-buffer-usage \
2 // RUN: -fsafe-buffer-usage-suggestions \
3 // RUN: -verify %s
4
5 // CHECK-NOT: [-Wunsafe-buffer-usage]
6
7
8 void foo(unsigned idx) {
9 int buffer[10]; // expected-warning{{'buffer' is an unsafe buffer that does not perform bounds checks}}
10 // expected-note@-1{{change type of 'buffer' to 'std::array' to label it for hardening}}
11 buffer[idx] = 0; // expected-note{{used in buffer access here}}
12 }
13
14 int global_buffer[10]; // expected-warning{{'global_buffer' is an unsafe buffer that does not perform bounds checks}}
15 void foo2(unsigned idx) {
16 global_buffer[idx] = 0; // expected-note{{used in buffer access here}}
17 }
18
19 struct Foo {
20 int member_buffer[10];
21 };
22 void foo2(Foo& f, unsigned idx) {
23 f.member_buffer[idx] = 0; // expected-warning{{unsafe buffer access}}
24 }
25
26 void constant_idx_safe(unsigned idx) {
27 int buffer[10];
28 buffer[9] = 0;
29 }
30
31 void constant_idx_safe0(unsigned idx) {
32 int buffer[10];
33 buffer[0] = 0;
34 }
35
36 void constant_idx_unsafe(unsigned idx) {
37 int buffer[10]; // expected-warning{{'buffer' is an unsafe buffer that does not perform bounds checks}}
38 // expected-note@-1{{change type of 'buffer' to 'std::array' to label it for hardening}}
39 buffer[10] = 0; // expected-note{{used in buffer access here}}
40 }