[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Sema / c2x-noreturn.c
blobcc276877c28603ed7e6eab087681eeab8e89f617
1 // RUN: %clang_cc1 -verify=all,c2x -std=c2x -fsyntax-only %s
2 // RUN: %clang_cc1 -verify=all -std=c17 -fdouble-square-bracket-attributes -fsyntax-only %s
3 // RUN: %clang_cc1 -verify=none -Wno-deprecated-attributes -D_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS -std=c2x -fsyntax-only %s
4 // RUN: %clang_cc1 -verify=none -Wno-deprecated-attributes -D_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS -std=c17 -fdouble-square-bracket-attributes -fsyntax-only %s
5 // none-no-diagnostics
7 // Test preprocessor functionality.
8 #if !__has_c_attribute(noreturn)
9 #error "No noreturn attribute support?"
10 #endif
12 #if !__has_c_attribute(_Noreturn)
13 #error "No _Noreturn attribute support?"
14 #endif
16 #if __has_c_attribute(noreturn) != __has_c_attribute(_Noreturn) || \
17 __has_c_attribute(noreturn) != 202202L
18 #error "Wrong value for __has_c_attribute(noreturn)"
19 #endif
21 // If we're testings with deprecations disabled, we don't care about testing
22 // the scenarios that trigger errors because we're only interested in the
23 // deprecation warning behaviors.
24 #ifndef _CLANG_DISABLE_CRT_DEPRECATION_WARNINGS
25 // Test that the attribute accepts no args, applies to the correct subject, etc.
26 [[noreturn(12)]] void func4(void); // all-error {{attribute 'noreturn' cannot have an argument list}}
27 [[noreturn]] int not_a_func; // all-error {{'noreturn' attribute only applies to functions}}
28 void func5(void) [[noreturn]]; // all-error {{'noreturn' attribute cannot be applied to types}}
29 #endif
31 _Noreturn void func1(void); // ok, using the function specifier
32 [[noreturn]] void func2(void);
34 // This is deprecated because it's only for compatibility with inclusion of the
35 // <stdnoreturn.h> header where the noreturn macro expands to _Noreturn.
36 [[_Noreturn]] void func3(void); // all-warning {{the '[[_Noreturn]]' attribute spelling is deprecated in C2x; use '[[noreturn]]' instead}}
38 // Test the behavior of including <stdnoreturn.h>
39 #include <stdnoreturn.h>
41 [[noreturn]] void func6(void);
43 void func7 [[noreturn]] (void);
45 noreturn void func8(void);
47 // Ensure the function specifier form still works.
48 void noreturn func9(void);
50 // Ensure that spelling the deprecated form of the attribute is still diagnosed.
51 [[_Noreturn]] void func10(void); // all-warning {{the '[[_Noreturn]]' attribute spelling is deprecated in C2x; use '[[noreturn]]' instead}}
53 // Test preprocessor functionality after including <stdnoreturn.h>.
54 #if !__has_c_attribute(noreturn)
55 #error "No noreturn attribute support?"
56 #endif
58 #if !__has_c_attribute(_Noreturn)
59 #error "No _Noreturn attribute support?"
60 #endif
62 // Test that a macro which expands to _Noreturn is still diagnosed when it
63 // doesn't come from a system header.
64 #define NORETURN _Noreturn
65 [[NORETURN]] void func11(void); // all-warning {{the '[[_Noreturn]]' attribute spelling is deprecated in C2x; use '[[noreturn]]' instead}}