[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Preprocessor / has_c_attribute.c
blob1da4d0541e6e0da573badf57c0a7899487238a4f
1 // RUN: %clang_cc1 -fdouble-square-bracket-attributes -std=c11 -E -P %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -std=c2x -E -P %s -o - | FileCheck %s
4 #define C2x(x) x: __has_c_attribute(x)
6 // CHECK: fallthrough: 201910L
7 C2x(fallthrough)
9 // CHECK: __nodiscard__: 202003L
10 C2x(__nodiscard__)
12 // CHECK: selectany: 0
13 C2x(selectany); // Known attribute not supported in C mode
15 // CHECK: frobble: 0
16 C2x(frobble) // Unknown attribute
18 // CHECK: frobble::frobble: 0
19 C2x(frobble::frobble) // Unknown vendor namespace
21 // CHECK: clang::annotate: 1
22 C2x(clang::annotate)
24 // CHECK: deprecated: 201904L
25 C2x(deprecated)
27 // CHECK: maybe_unused: 202106L
28 C2x(maybe_unused)
30 // CHECK: __gnu__::warn_unused_result: 202003L
31 C2x(__gnu__::warn_unused_result)
33 // CHECK: gnu::__warn_unused_result__: 202003L
34 C2x(gnu::__warn_unused_result__)
36 // Test that macro expansion of the builtin argument works.
37 #define C clang
38 #define L likely
39 #define CL clang::likely
40 #define N nodiscard
42 #if __has_c_attribute(N)
43 int has_nodiscard;
44 #endif
45 // CHECK: int has_nodiscard;
47 #if __has_c_attribute(C::L)
48 int has_clang_likely_1;
49 #endif
50 // CHECK: int has_clang_likely_1;
52 #if __has_c_attribute(clang::L)
53 int has_clang_likely_2;
54 #endif
55 // CHECK: int has_clang_likely_2;
57 #if __has_c_attribute(C::likely)
58 int has_clang_likely_3;
59 #endif
60 // CHECK: int has_clang_likely_3;
62 #if __has_c_attribute(CL)
63 int has_clang_likely_4;
64 #endif
65 // CHECK: int has_clang_likely_4;
67 #define FUNCLIKE1(x) clang::x
68 #if __has_c_attribute(FUNCLIKE1(likely))
69 int funclike_1;
70 #endif
71 // CHECK: int funclike_1;
73 #define FUNCLIKE2(x) _Clang::x
74 #if __has_c_attribute(FUNCLIKE2(likely))
75 int funclike_2;
76 #endif
77 // CHECK: int funclike_2;