https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/218669
>From 0b20f92079d1bd732535cc694e27da57a9177170 Mon Sep 17 00:00:00 2001 From: Aaron Ballman <[email protected]> Date: Tue, 25 Aug 2026 08:16:28 -0400 Subject: [PATCH 1/2] Give the __COUNTER__ pedantic diagnostic a group Adding the pedantic diagnostic after supporting the extension for so long without correctly diagnosing it is disruptive, so this gives folks a way to disable just the __COUNTER__ pedantic diagnostic without losing all other pedantic diagnostics. Fixes #196557 --- clang/include/clang/Basic/DiagnosticGroups.td | 3 ++- clang/include/clang/Basic/DiagnosticLexKinds.td | 3 ++- clang/test/C/C2y/n3457.c | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 9ee0b61a96a32..7af6a3b2d284c 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1026,6 +1026,7 @@ def SuspiciousMemaccess : DiagGroup<"suspicious-memaccess", NonTrivialMemaccess, MemsetTransposedArgs, SuspiciousBzero]>; def StaticInInline : DiagGroup<"static-in-inline">; def StaticLocalInInline : DiagGroup<"static-local-in-inline">; +def CounterExt : DiagGroup<"counter-extension">; def UniqueObjectDuplication : DiagGroup<"unique-object-duplication"> { code Documentation = [{ Warns when objects which are supposed to be globally unique might get duplicated @@ -1616,7 +1617,7 @@ def C23 : DiagGroup<"c23-extensions", [VariadicMacroArgumentsOmitted]>; def : DiagGroup<"c2x-extensions", [C23]>; // A warning group for warnings about using C2y features as extensions. -def C2y : DiagGroup<"c2y-extensions", [StaticInInline]>; +def C2y : DiagGroup<"c2y-extensions", [StaticInInline, CounterExt]>; // Previously supported warning group which is no longer pertinent as binary // literals are a C++14 and C23 extension now instead of a GNU extension. diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index bdb78ed80b7b4..291ebba95b9cf 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -93,7 +93,8 @@ def err_conflict_marker : Error<"version control conflict marker in file">; def err_counter_overflow : Error< "'__COUNTER__' value cannot exceed 2'147'483'647">; def ext_counter : Extension< - "'__COUNTER__' is a C2y extension">, InGroup<C2y>, SuppressInSystemMacro; + "'__COUNTER__' is a C2y extension">, + InGroup<CounterExt>, SuppressInSystemMacro; def warn_counter : Warning< "'__COUNTER__' is incompatible with standards before C2y">, InGroup<CPre2yCompat>, DefaultIgnore, SuppressInSystemMacro; diff --git a/clang/test/C/C2y/n3457.c b/clang/test/C/C2y/n3457.c index d71a3f37e1343..a4733e9fed8b8 100644 --- a/clang/test/C/C2y/n3457.c +++ b/clang/test/C/C2y/n3457.c @@ -1,6 +1,9 @@ // RUN: %clang_cc1 -verify=ext -std=c23 -pedantic %s // RUN: %clang_cc1 -verify=ext -pedantic -x c++ %s // RUN: %clang_cc1 -verify=pre -std=c2y -pedantic -Wpre-c2y-compat %s +// RUN: %clang_cc1 -verify=ok -std=c23 -pedantic -Wno-counter-extension %s +// RUN: %clang_cc1 -verify=ok -std=c23 -Wno-counter-extension -pedantic-errors %s +// ok-no-diagnostics /* WG14 N3457: Clang 22 * The __COUNTER__ predefined macro >From 9a2e67a96db5a4eb4b9894febd46b4c20cf4cfcf Mon Sep 17 00:00:00 2001 From: Aaron Ballman <[email protected]> Date: Tue, 25 Aug 2026 09:06:02 -0400 Subject: [PATCH 2/2] Add release note --- clang/docs/ReleaseNotes.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 8cc8eb5f80066..a15c80dd5efbe 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -421,6 +421,11 @@ features cannot lower the translation-unit ABI level; - `-Wc++98-compat` now diagnoses explicit conversion functions in C++20 and later, matching the behavior in C++11 through C++17. (#GH161689) +- Added `-Wcounter-extension` as a diagnostic group under `-Wc2y-extensions` to + control `__COUNTER__` being diagnosed as an extension. This allows `-pedantic` + users to disable the diagnostic with `-Wno-counter-extension` without having + to disable all pedantic diagnostics. (#GH196557) + ### Improvements to Clang's time-trace ### Improvements to Coverage Mapping _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
