Author: Anutosh Bhat
Date: 2025-06-05T11:23:50+05:30
New Revision: 7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0

URL: 
https://github.com/llvm/llvm-project/commit/7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0
DIFF: 
https://github.com/llvm/llvm-project/commit/7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0.diff

LOG: [clang-repl] Ensure clang-repl accepts all C keywords supported in all 
language models (#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`

Added: 
    

Modified: 
    clang/lib/Parse/ParseTentative.cpp
    clang/test/Interpreter/disambiguate-decl-stmt.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseTentative.cpp 
b/clang/lib/Parse/ParseTentative.cpp
index 95cee824c40b7..f50bcd8ea90bb 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1171,6 +1171,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext 
AllowImplicitTypename,
   case tok::kw_inline:
   case tok::kw_virtual:
   case tok::kw_explicit:
+  case tok::kw__Noreturn:
 
     // Modules
   case tok::kw___module_private__:
@@ -1225,6 +1226,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext 
AllowImplicitTypename,
     // GNU
   case tok::kw_restrict:
   case tok::kw__Complex:
+  case tok::kw__Imaginary:
   case tok::kw___attribute:
   case tok::kw___auto_type:
     return TPResult::True;

diff  --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp 
b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
index 1f4d5e267288b..f2a59c510f9a2 100644
--- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -102,3 +102,16 @@ __attribute((noreturn)) Attrs2::Attrs2() = default;
 
 // Extra semicolon
 namespace N {};
+
+// Test C keywords supported in all language modes.
+// 
https://clang.llvm.org/docs/LanguageExtensions.html#c-keywords-supported-in-all-language-modes
+
+_Alignas(16) int aligned_var;
+int align = _Alignof(double);
+_Atomic int atomic_var = 0;
+_Complex double complex_val = 1.0 + 2.0i;
+_Float16 f = 1.5;
+_Thread_local int counter = 0;
+_Static_assert(sizeof(int) == 4, "int must be 4 bytes");
+_Imaginary float i = 2.0f; // expected-error {{imaginary types are not 
supported}}
+_Noreturn void noreturn_func() { while (true) {} }
\ No newline at end of file


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to