xref: /llvm-project/clang/test/SemaCXX/warn-unsafe-buffer-usage-c-linkage.cpp (revision d1ae844dc2cc58bc762135d9500464c61d50f4f9)
1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions -verify %s
2 
3 extern "C" {
foo(int * ptr)4 void foo(int *ptr) {
5   ptr[5] = 10;  // expected-warning{{unsafe buffer access}}
6 }
7 
8 void bar(int *ptr);
9 
10 struct c_struct {
11   char *name;
12 };
13 }
14 
bar(int * ptr)15 void bar(int *ptr) {
16   ptr[5] = 10;  // expected-warning{{unsafe buffer access}}
17 }
18 
call_foo(int * p)19 void call_foo(int *p) {
20   foo(p);
21   struct c_struct str;
22   str.name[7] = 9;  // expected-warning{{unsafe buffer access}}
23   bar(p);
24 }
25