[clang] [C2y] Support WG14 N3457, the __COUNTER__ macro (PR #162662)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 9 09:10:34 PDT 2025


================
@@ -1737,7 +1737,18 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
       Diag(getLastFPEvalPragmaLocation(), diag::note_pragma_entered_here);
     }
   } else if (II == Ident__COUNTER__) {
-    // __COUNTER__ expands to a simple numeric value.
+    Diag(Tok.getLocation(),
+         getLangOpts().C2y ? diag::warn_counter : diag::ext_counter);
+    // __COUNTER__ expands to a simple numeric value that must be less than
+    // 2147483647.
+    if (CounterValue > 2147483647) {
----------------
AaronBallman wrote:

Makes sense, done!

https://github.com/llvm/llvm-project/pull/162662


More information about the cfe-commits mailing list