[clang] 194b860 - Give the __COUNTER__ pedantic diagnostic a group (#218669)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 31 05:26:53 PDT 2026
Author: Aaron Ballman
Date: 2026-08-31T12:26:48Z
New Revision: 194b86001c776d2d951f5fe70c78d6e8d34342f8
URL: https://github.com/llvm/llvm-project/commit/194b86001c776d2d951f5fe70c78d6e8d34342f8
DIFF: https://github.com/llvm/llvm-project/commit/194b86001c776d2d951f5fe70c78d6e8d34342f8.diff
LOG: Give the __COUNTER__ pedantic diagnostic a group (#218669)
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
Added:
Modified:
clang/docs/ReleaseNotes.md
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/test/C/C2y/n3457.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 32ee602dc8472..053a132e2408a 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -427,6 +427,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)
+
- Clang now diagnoses more details when a constraint evaluates to false.
### Improvements to Clang's time-trace
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 5403fadccd5d2..17b4d0d393e50 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
More information about the cfe-commits
mailing list