|
| 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 |
| 6 | + |
| 7 | +// Test preprocessor functionality. |
| 8 | +#if !__has_c_attribute(noreturn) |
| 9 | +#error "No noreturn attribute support?" |
| 10 | +#endif |
| 11 | + |
| 12 | +#if !__has_c_attribute(_Noreturn) |
| 13 | +#error "No _Noreturn attribute support?" |
| 14 | +#endif |
| 15 | + |
| 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 |
| 20 | + |
| 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 |
| 30 | + |
| 31 | +_Noreturn void func1(void); // ok, using the function specifier |
| 32 | +[[noreturn]] void func2(void); |
| 33 | + |
| 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}} |
| 37 | + |
| 38 | +// Test the behavior of including <stdnoreturn.h> |
| 39 | +#include <stdnoreturn.h> // [email protected]:* {{the '<stdnoreturn.h>' header is deprecated in C2x}} |
| 40 | + |
| 41 | +[[noreturn]] void func6(void); // all-warning {{the '[[_Noreturn]]' attribute spelling is deprecated in C2x; use '[[noreturn]]' instead}} \ |
| 42 | + // c2x-warning {{macro 'noreturn' has been marked as deprecated}} \ |
| 43 | + // [email protected]:* {{macro marked 'deprecated' here}} |
| 44 | + |
| 45 | +void func7 [[noreturn]] (void); // all-warning {{the '[[_Noreturn]]' attribute spelling is deprecated in C2x; use '[[noreturn]]' instead}} \ |
| 46 | + // c2x-warning {{macro 'noreturn' has been marked as deprecated}} \ |
| 47 | + // [email protected]:* {{macro marked 'deprecated' here}} |
| 48 | + |
| 49 | +noreturn void func8(void); // c2x-warning {{macro 'noreturn' has been marked as deprecated}} \ |
| 50 | + // [email protected]:* {{macro marked 'deprecated' here}} |
| 51 | + |
| 52 | +// Ensure the function specifier form still works |
| 53 | +void noreturn func9(void); // c2x-warning {{macro 'noreturn' has been marked as deprecated}} \ |
| 54 | + // [email protected]:* {{macro marked 'deprecated' here}} |
| 55 | + |
| 56 | +// Test preprocessor functionality after including <stdnoreturn.h>. |
| 57 | +#if !__has_c_attribute(noreturn) // c2x-warning {{macro 'noreturn' has been marked as deprecated}} \ |
| 58 | + // [email protected]:* {{macro marked 'deprecated' here}} |
| 59 | +#error "No noreturn attribute support?" |
| 60 | +#endif |
| 61 | + |
| 62 | +#if !__has_c_attribute(_Noreturn) |
| 63 | +#error "No _Noreturn attribute support?" |
| 64 | +#endif |
0 commit comments