File: c2x-noreturn.c

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (65 lines) | stat: -rw-r--r-- 2,822 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// RUN: %clang_cc1 -verify=all,c2x -std=c2x -fsyntax-only %s
// RUN: %clang_cc1 -verify=all -std=c17 -fdouble-square-bracket-attributes -fsyntax-only %s
// RUN: %clang_cc1 -verify=none -Wno-deprecated-attributes -D_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS -std=c2x -fsyntax-only %s
// RUN: %clang_cc1 -verify=none -Wno-deprecated-attributes -D_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS -std=c17 -fdouble-square-bracket-attributes -fsyntax-only %s
// none-no-diagnostics

// Test preprocessor functionality.
#if !__has_c_attribute(noreturn)
#error "No noreturn attribute support?"
#endif

#if !__has_c_attribute(_Noreturn)
#error "No _Noreturn attribute support?"
#endif

#if __has_c_attribute(noreturn) != __has_c_attribute(_Noreturn) || \
    __has_c_attribute(noreturn) != 202202L
#error "Wrong value for __has_c_attribute(noreturn)"
#endif

// If we're testings with deprecations disabled, we don't care about testing
// the scenarios that trigger errors because we're only interested in the
// deprecation warning behaviors.
#ifndef _CLANG_DISABLE_CRT_DEPRECATION_WARNINGS
// Test that the attribute accepts no args, applies to the correct subject, etc.
[[noreturn(12)]] void func4(void); // all-error {{attribute 'noreturn' cannot have an argument list}}
[[noreturn]] int not_a_func; // all-error {{'noreturn' attribute only applies to functions}}
void func5(void) [[noreturn]]; // all-error {{'noreturn' attribute cannot be applied to types}}
#endif

_Noreturn void func1(void); // ok, using the function specifier
[[noreturn]] void func2(void);

// This is deprecated because it's only for compatibility with inclusion of the
// <stdnoreturn.h> header where the noreturn macro expands to _Noreturn.
[[_Noreturn]] void func3(void); // all-warning {{the '[[_Noreturn]]' attribute spelling is deprecated in C2x; use '[[noreturn]]' instead}}

// Test the behavior of including <stdnoreturn.h>
#include <stdnoreturn.h>

[[noreturn]] void func6(void);

void func7 [[noreturn]] (void);

noreturn void func8(void);

// Ensure the function specifier form still works.
void noreturn func9(void);

// Ensure that spelling the deprecated form of the attribute is still diagnosed.
[[_Noreturn]] void func10(void); // all-warning {{the '[[_Noreturn]]' attribute spelling is deprecated in C2x; use '[[noreturn]]' instead}}

// Test preprocessor functionality after including <stdnoreturn.h>.
#if !__has_c_attribute(noreturn)
#error "No noreturn attribute support?"
#endif

#if !__has_c_attribute(_Noreturn)
#error "No _Noreturn attribute support?"
#endif

// Test that a macro which expands to _Noreturn is still diagnosed when it
// doesn't come from a system header.
#define NORETURN _Noreturn
[[NORETURN]] void func11(void); // all-warning {{the '[[_Noreturn]]' attribute spelling is deprecated in C2x; use '[[noreturn]]' instead}}