Skip to content

Commit 2ebdc7c

Browse files
anutosh491rorth
authored andcommitted
[clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (llvm#142749)
As can be seen through the docs (https://github.com/llvm/llvm-project/blob/7e1fa09ce2a228c949ce4490c98f2c73ed8ada00/clang/docs/LanguageExtensions.rst#c-keywords-supported-in-all-language-modes), Clang supports certain C keywords in all language modes — this patch ensures clang-repl handles them consistently. Here's an example testing all the above keywords. We have everything in place except `_Imaginary` (_Complex works but _Imaginary doesn't which was weird) and `_Noreturn`
1 parent 49245c9 commit 2ebdc7c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/lib/Parse/ParseTentative.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
11711171
case tok::kw_inline:
11721172
case tok::kw_virtual:
11731173
case tok::kw_explicit:
1174+
case tok::kw__Noreturn:
11741175

11751176
// Modules
11761177
case tok::kw___module_private__:
@@ -1225,6 +1226,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
12251226
// GNU
12261227
case tok::kw_restrict:
12271228
case tok::kw__Complex:
1229+
case tok::kw__Imaginary:
12281230
case tok::kw___attribute:
12291231
case tok::kw___auto_type:
12301232
return TPResult::True;

clang/test/Interpreter/disambiguate-decl-stmt.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,16 @@ __attribute((noreturn)) Attrs2::Attrs2() = default;
102102

103103
// Extra semicolon
104104
namespace N {};
105+
106+
// Test C keywords supported in all language modes.
107+
// https://clang.llvm.org/docs/LanguageExtensions.html#c-keywords-supported-in-all-language-modes
108+
109+
_Alignas(16) int aligned_var;
110+
int align = _Alignof(double);
111+
_Atomic int atomic_var = 0;
112+
_Complex double complex_val = 1.0 + 2.0i;
113+
_Float16 f = 1.5;
114+
_Thread_local int counter = 0;
115+
_Static_assert(sizeof(int) == 4, "int must be 4 bytes");
116+
_Imaginary float i = 2.0f; // expected-error {{imaginary types are not supported}}
117+
_Noreturn void noreturn_func() { while (true) {} }

0 commit comments

Comments
 (0)