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 ...
9 // Will use the macro defined from the command line:
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
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]]
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>)"
29 #if __has_cpp_attribute(clang::unsafe_buffer_usage)
30 #define UNSAFE_ATTR [[clang::unsafe_buffer_usage]]
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>)"
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]]
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>)"
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]]`
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
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)"