Skip to content

Commit e918986

Browse files
author
MalavikaSamak
committed
Adding a test to check behavior with templated methods.
1 parent b37f48f commit e918986

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

clang/test/SemaCXX/warn-unsafe-buffer-usage-function-attr.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,20 @@ void check_no_warning_variadic(unsigned idx, int arr[20], ...) {
291291
a.ptr = arr; // no-warning
292292
}
293293

294+
template<typename T>
295+
[[clang::unsafe_buffer_usage]]
296+
void check_no_warnings_template(unsigned idx, T* arr) {
297+
int k = arr[idx]; // no-warning
298+
299+
std::span<int> sp = {arr, 20}; // no-warning
300+
A *ptr = reinterpret_cast<A*> (sp.data()); // no-warning
301+
A a;
302+
a.ptr = arr; // no-warning
303+
}
304+
294305
void invoke_methods() {
295306
int array[20];
296307
check_no_warnings(30); //expected-warning{{function introduces unsafe buffer manipulation}}
297-
check_no_warning_variadic(20, array); //expected-warning{{function introduces unsafe buffer manipulation}}
308+
check_no_warning_variadic(15, array); //expected-warning{{function introduces unsafe buffer manipulation}}
309+
check_no_warnings_template(10, array); //expected-warning{{function introduces unsafe buffer manipulation}}
298310
}

0 commit comments

Comments
 (0)