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}}
93 [[clang::unsafe_buffer_usage
]]
96 [[clang::unsafe_buffer_usage
]]
97 explicit operator int() { return 0; }
99 [[clang::unsafe_buffer_usage
]]
102 [[clang::unsafe_buffer_usage
]]
105 [[clang::unsafe_buffer_usage
]]
106 int operator+(UnsafeMembers
) { return 0; }
109 template <class... Vs
>
110 int testFoldExpression(Vs
&&... v
) {
111 return (... + v
); // expected-warning{{function introduces unsafe buffer manipulation}}
114 // https://github.com/llvm/llvm-project/issues/80482
115 void testClassMembers() {
116 UnsafeMembers(3); // expected-warning{{function introduces unsafe buffer manipulation}}
118 (void)static_cast<int>(UnsafeMembers()); // expected-warning{{function introduces unsafe buffer manipulation}}
120 UnsafeMembers().Method(); // expected-warning{{function introduces unsafe buffer manipulation}}
122 UnsafeMembers()(); // expected-warning{{function introduces unsafe buffer manipulation}}
124 testFoldExpression(UnsafeMembers(), UnsafeMembers());