106 lines · c
1// RUN: %clang_cc1 -std=c99 -E %s -o - | FileCheck --check-prefix=CHECK-NONE %s2 3// RUN: %clang_cc1 -std=gnu89 -E %s -o - \4// RUN: | FileCheck --check-prefix=CHECK-GNU-KEYWORDS %s5// RUN: %clang_cc1 -std=c99 -fgnu-keywords -E %s -o - \6// RUN: | FileCheck --check-prefix=CHECK-GNU-KEYWORDS %s7// RUN: %clang_cc1 -std=gnu89 -fno-gnu-keywords -E %s -o - \8// RUN: | FileCheck --check-prefix=CHECK-NONE %s9 10// RUN: %clang_cc1 -std=c99 -fms-extensions -fms-compatibility -E %s -o - \11// RUN: | FileCheck --check-prefix=CHECK-MS-KEYWORDS %s12// RUN: %clang_cc1 -std=c99 -fdeclspec -E %s -o - \13// RUN: | FileCheck --check-prefix=CHECK-DECLSPEC-KEYWORD %s14// RUN: %clang_cc1 -std=c99 -fms-extensions -fno-declspec -E %s -o - \15// RUN: | FileCheck --check-prefix=CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC %s16 17// RUN: %clang_cc1 -std=c99 -DC99 -fsyntax-only %s18// RUN: %clang_cc1 -std=c2x -DC99 -DC2x -fsyntax-only %s19 20// RUN: %clang_cc1 -fsyntax-only -std=c89 -DFutureKeyword -Wc2x-compat -Wc99-compat -verify=c89 %s21 22#define IS_KEYWORD(NAME) _Static_assert(!__is_identifier(NAME), #NAME)23#define NOT_KEYWORD(NAME) _Static_assert(__is_identifier(NAME), #NAME)24 25#if defined(C99)26#define C99_KEYWORD(NAME) IS_KEYWORD(NAME)27#else28#define C99_KEYWORD(NAME) NOT_KEYWORD(NAME)29#endif30 31#if defined(C2x)32#define C2x_KEYWORD(NAME) IS_KEYWORD(NAME)33#else34#define C2x_KEYWORD(NAME) NOT_KEYWORD(NAME)35#endif36 37// C99 Keywords.38C99_KEYWORD(restrict);39C99_KEYWORD(inline);40 41// C2x Keywords.42C2x_KEYWORD(bool);43C2x_KEYWORD(true);44C2x_KEYWORD(false);45C2x_KEYWORD(static_assert);46C2x_KEYWORD(typeof);47C2x_KEYWORD(typeof_unqual);48C2x_KEYWORD(thread_local);49C2x_KEYWORD(alignas);50C2x_KEYWORD(alignof);51 52void f() {53// CHECK-NONE: int asm54// CHECK-GNU-KEYWORDS: asm ("ret" : :)55#if __is_identifier(asm)56 int asm;57#else58 asm ("ret" : :);59#endif60}61 62// CHECK-NONE: no_ms_wchar63// CHECK-MS-KEYWORDS: has_ms_wchar64// CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC: has_ms_wchar65#if __is_identifier(__wchar_t)66void no_ms_wchar();67#else68void has_ms_wchar();69#endif70 71// CHECK-NONE: no_declspec72// CHECK-MS-KEYWORDS: has_declspec73// CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC: no_declspec74// CHECK-DECLSPEC-KEYWORD: has_declspec75#if __is_identifier(__declspec)76void no_declspec();77#else78void has_declspec();79#endif80 81// CHECK-NONE: no_static_assert82// CHECK-GNU-KEYWORDS: no_static_assert83// CHECK-MS-KEYWORDS: has_static_assert84// CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC: no_static_assert85#if __is_identifier(static_assert)86void no_static_assert();87#else88void has_static_assert();89#endif90 91#ifdef FutureKeyword92 93 int restrict; // c89-warning {{'restrict' is a keyword in C99}}94 int inline; // c89-warning {{'inline' is a keyword in C99}}95 96 int bool; // c89-warning {{'bool' is a keyword in C23}}97 char true; // c89-warning {{'true' is a keyword in C23}}98 char false; // c89-warning {{'false' is a keyword in C23}}99 float alignof; // c89-warning {{'alignof' is a keyword in C23}}100 int typeof; // c89-warning {{'typeof' is a keyword in C23}}101 int typeof_unqual; // c89-warning {{'typeof_unqual' is a keyword in C23}}102 int alignas; // c89-warning {{'alignas' is a keyword in C23}}103 int static_assert; // c89-warning {{'static_assert' is a keyword in C23}}104 105#endif106