1 // RUN: %clang_cc1 -verify=all,c2x -std=c2x -fsyntax-only %s
2 // RUN: %clang_cc1 -verify=all -std=c17 -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 -fsyntax-only %s
7 // Test preprocessor functionality.
8 #if !__has_c_attribute(noreturn)
9 #error "No noreturn attribute support?"
12 #if !__has_c_attribute(_Noreturn)
13 #error "No _Noreturn attribute support?"
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)"
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}}
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 C23; 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 C23; use '[[noreturn]]' instead}}
53 // Test preprocessor functionality after including <stdnoreturn.h>.
54 #if !__has_c_attribute(noreturn)
55 #error "No noreturn attribute support?"
58 #if !__has_c_attribute(_Noreturn)
59 #error "No _Noreturn attribute support?"
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 C23; use '[[noreturn]]' instead}}