1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
2 // RUN: -fsafe-buffer-usage-suggestions -verify %s
4 [[clang::unsafe_buffer_usage
]]
5 void deprecatedFunction3();
7 void deprecatedFunction4(int z
);
11 [[clang::unsafe_buffer_usage
]]
12 void overloading(int* x
);
14 void overloading(char c
[]);
16 void overloading(int* x
, int size
);
18 [[clang::unsafe_buffer_usage
]]
19 void deprecatedFunction4(int z
);
21 void caller(int z
, int* x
, int size
, char c
[]) {
22 deprecatedFunction3(); // expected-warning{{function introduces unsafe buffer manipulation}}
23 deprecatedFunction4(z
); // expected-warning{{function introduces unsafe buffer manipulation}}
26 overloading(x
); // expected-warning{{function introduces unsafe buffer manipulation}}
31 [[clang::unsafe_buffer_usage
]]
32 void overloading(char c
[]);
35 [[clang::unsafe_buffer_usage
]]
36 void testVariadics(int *ptr
, ...);
38 template<typename T
, typename
... Args
>
39 [[clang::unsafe_buffer_usage
]]
40 T
adder(T first
, Args
... args
);
46 [[clang::unsafe_buffer_usage
]]
47 void foo
<int *>(int *t
) {}
49 void caller1(int *p
, int *q
) {
50 testVariadics(p
, q
); // expected-warning{{function introduces unsafe buffer manipulation}}
51 adder(p
, q
); // expected-warning{{function introduces unsafe buffer manipulation}}
55 foo(&x
); // expected-warning{{function introduces unsafe buffer manipulation}}
58 // Test virtual functions
61 [[clang::unsafe_buffer_usage
]]
62 virtual void func() {}
64 virtual void func1() {}
67 class DerivedClass
: public BaseClass
{
71 [[clang::unsafe_buffer_usage
]]
75 void testInheritance() {
78 DC
.func1(); // expected-warning{{function introduces unsafe buffer manipulation}}
81 BC
->func(); // expected-warning{{function introduces unsafe buffer manipulation}}
85 BC
->func(); // expected-warning{{function introduces unsafe buffer manipulation}}