[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / warn-unsafe-buffer-usage-fixits-attributes-spelling.cpp
blob1b2f8bc9fa1b814778e2821e7e77b6dd4a90c030
1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits -fsafe-buffer-usage-suggestions -DCMD_UNSAFE_ATTR=[[clang::unsafe_buffer_usage]] %s 2>&1 | FileCheck %s
4 // no need to check fix-its for definition in this test ...
5 void foo(int *p) {
6 int tmp = p[5];
9 // Will use the macro defined from the command line:
10 void foo(int *);
11 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"CMD_UNSAFE_ATTR "
12 // CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)"
15 #undef CMD_UNSAFE_ATTR
16 void foo(int *);
17 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}} "
18 // CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)"
21 #define UNSAFE_ATTR [[clang::unsafe_buffer_usage]]
23 void foo(int *);
24 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"UNSAFE_ATTR "
25 // CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)"
27 #undef UNSAFE_ATTR
29 #if __has_cpp_attribute(clang::unsafe_buffer_usage)
30 #define UNSAFE_ATTR [[clang::unsafe_buffer_usage]]
31 #endif
33 void foo(int *);
34 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"UNSAFE_ATTR "
35 // CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)"
37 #undef UNSAFE_ATTR
39 #if __has_cpp_attribute(clang::unsafe_buffer_usage)
40 // we don't know how to use this macro
41 #define UNSAFE_ATTR(x) [[clang::unsafe_buffer_usage]]
42 #endif
44 void foo(int *);
45 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}} "
46 // CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)"
48 #undef UNSAFE_ATTR
50 #define UNSAFE_ATTR_1 [[clang::unsafe_buffer_usage]]
51 #define UNSAFE_ATTR_2 [[clang::unsafe_buffer_usage]]
52 #define UNSAFE_ATTR_3 [[clang::unsafe_buffer_usage]]
54 // Should use the last defined macro (i.e., UNSAFE_ATTR_3) for
55 // `[[clang::unsafe_buffer_usage]]`
56 void foo(int *p);
57 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"UNSAFE_ATTR_3 "
58 // CHECK: fix-it:{{.*}}:{[[@LINE-2]]:17-[[@LINE-2]]:17}:";\nvoid foo(std::span<int> p)"
61 #define WRONG_ATTR_1 [clang::unsafe_buffer_usage]]
62 #define WRONG_ATTR_2 [[clang::unsafe_buffer_usage]
63 #define WRONG_ATTR_3 [[clang::unsafe_buffer_usag]]
65 // The last defined macro for
66 // `[[clang::unsafe_buffer_usage]]` is still UNSAFE_ATTR_3
67 void foo(int *p);
68 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"UNSAFE_ATTR_3 "
69 // CHECK: fix-it:{{.*}}:{[[@LINE-2]]:17-[[@LINE-2]]:17}:";\nvoid foo(std::span<int> p)"