[clang-tools-extra] [clang-tidy] Stop ignoring `-std` argument in `check_clang_tidy.py` for C files (PR #150791)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 26 12:06:34 PDT 2025
https://github.com/localspook created https://github.com/llvm/llvm-project/pull/150791
Before, the tests were run with whatever Clang defaults to when you don't specify a standard.
The tests are adapted to account for various things:
- `typeof` is changed to `__typeof__`; the non-`__ugly__` spelling is only available with GNU extensions or C23.
- In C23, `bool` is a keyword, so `typedef foo bool;` is invalid.
- In C23, `f()` means `f(void)`, not "takes arbitrary parameters".
- In C23, K&R-style function definitions are removed.
We could also, instead of making the autodetection logic in `check_clang_tidy.py` more elaborate, force all tests to specify `-std` explicitly.
>From 3afe548daa11ff8f1f21f4c016bc905c308c15c3 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <chernyakin.victor.j at outlook.com>
Date: Sat, 26 Jul 2025 11:52:19 -0700
Subject: [PATCH] [clang-tidy] Stop ignoring `-std` argument in
`check_clang_tidy.py` for C files
---
.../test/clang-tidy/check_clang_tidy.py | 17 ++++++++---
.../checkers/Inputs/Headers/system-other.h | 2 ++
...rison-in-temp-failure-retry-custom-macro.c | 4 +--
.../comparison-in-temp-failure-retry.c | 4 +--
.../bugprone/branch-clone-macro-crash.c | 10 +++----
.../easily-swappable-parameters-relatedness.c | 16 ++++++-----
.../bugprone/easily-swappable-parameters.c | 28 +++++++++++++++----
...rminated-result-in-initialization-strlen.c | 2 +-
...ull-terminated-result-memcpy-before-safe.c | 2 +-
.../not-null-terminated-result-memcpy-safe.c | 2 +-
...-result-stdc-want-lib-ext1-not-a-literal.c | 2 +-
.../not-null-terminated-result-strlen.c | 2 +-
...rminated-result-undef-stdc-want-lib-ext1.c | 2 +-
.../checkers/bugprone/signal-handler.c | 7 +++--
.../checkers/bugprone/sizeof-expression.c | 4 +--
.../checkers/bugprone/unsafe-functions.c | 12 ++++----
.../checkers/google/objc-function-naming.m | 2 +-
.../clang-tidy/checkers/misc/static-assert.c | 2 +-
.../checkers/misc/unused-parameters.c | 8 ++++--
.../checkers/modernize/use-nullptr-c23.c | 2 +-
.../checkers/readability/bitint-no-crash.c | 3 +-
.../identifier-naming-standard-types.h | 2 +-
.../readability/implicit-bool-conversion.c | 6 ++--
.../readability/non-const-parameter.c | 2 +-
24 files changed, 89 insertions(+), 54 deletions(-)
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 774bc970ef284..7e43c23d0e883 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -135,8 +135,7 @@ def __init__(self, args: argparse.Namespace, extra_args: List[str]) -> None:
"-fblocks",
] + self.clang_extra_args
- if extension in [".cpp", ".hpp", ".mm"]:
- self.clang_extra_args.append("-std=" + self.std)
+ self.clang_extra_args.append("-std=" + self.std)
# Tests should not rely on STL being available, and instead provide mock
# implementations of relevant APIs.
@@ -374,7 +373,7 @@ def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
parser.add_argument(
"-std",
type=csv,
- default=["c++11-or-later"],
+ default=None,
help="Passed to clang. Special -or-later values are expanded.",
)
parser.add_argument(
@@ -382,7 +381,17 @@ def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
action="store_true",
help="allow partial line matches for fixes",
)
- return parser.parse_known_args()
+
+ args, extra_args = parser.parse_known_args()
+ if args.std is None:
+ _, extension = os.path.splitext(args.assume_filename or args.input_file_name)
+ args.std = (
+ ["c++11-or-later"]
+ if extension in [".cpp", ".hpp", ".mm"]
+ else ["c99-or-later"]
+ )
+
+ return (args, extra_args)
def main() -> None:
diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h
index 28c26b73ba6b4..011c869d2b9a7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h
@@ -11,6 +11,8 @@
// Special system calls.
+#if __STDC_VERSION__ < 202311L
void other_call();
+#endif
#endif // _SYSTEM_OTHER_H_
diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c b/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c
index 56c382c87f1f3..3f60860e1f425 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c
@@ -2,7 +2,7 @@
#define MY_TEMP_FAILURE_RETRY(x) \
({ \
- typeof(x) __z; \
+ __typeof__(x) __z; \
do \
__z = (x); \
while (__z == -1); \
@@ -11,7 +11,7 @@
#define MY_OTHER_TEMP_FAILURE_RETRY(x) \
({ \
- typeof(x) __z; \
+ __typeof__(x) __z; \
do \
__z = (x); \
while (__z == -1); \
diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c b/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c
index 461fb4ad52542..1c71ebb75604e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c
@@ -2,7 +2,7 @@
#define TEMP_FAILURE_RETRY(x) \
({ \
- typeof(x) __z; \
+ __typeof__(x) __z; \
do \
__z = (x); \
while (__z == -1); \
@@ -130,7 +130,7 @@ void obscured_temp_failure_retry(void) {
#undef TEMP_FAILURE_RETRY
#define IMPL(x) \
({ \
- typeof(x) __z; \
+ __typeof__(x) __z; \
do \
__z = (x); \
while (__z == -1); \
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
index a4cb7347f88c6..0f4389c885e8f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
@@ -1,11 +1,11 @@
// RUN: %check_clang_tidy %s bugprone-branch-clone %t
int x = 0;
int y = 1;
-#define a(b, c) \
- typeof(b) d; \
- if (b) \
- d = b; \
- else if (c) \
+#define a(b, c) \
+ __typeof__(b) d; \
+ if (b) \
+ d = b; \
+ else if (c) \
d = b;
void f(void) {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-relatedness.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-relatedness.c
index 7231361a2e080..3d01f5745deaa 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-relatedness.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-relatedness.c
@@ -9,7 +9,6 @@
// RUN: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold: 0 \
// RUN: }}' -- -Wno-strict-prototypes -x c
-int myprint();
int add(int X, int Y);
void notRelated(int A, int B) {}
@@ -19,13 +18,16 @@ void notRelated(int A, int B) {}
int addedTogether(int A, int B) { return add(A, B); } // NO-WARN: Passed to same function.
+// FIXME: This triggers a false positive: the "passed to same function" heuristic
+// can't map the parameter index 1 to A and B because myprint() has no
+// parameters.
+// warning: 2 adjacent parameters of 'passedToSameKNRFunction' of similar type ('int')
+// note: the first parameter in the range is 'A'
+// note: the last parameter in the range is 'B'
+#if 0
+int myprint();
void passedToSameKNRFunction(int A, int B) {
myprint("foo", A);
myprint("bar", B);
}
-// CHECK-MESSAGES: :[[@LINE-4]]:30: warning: 2 adjacent parameters of 'passedToSameKNRFunction' of similar type ('int')
-// CHECK-MESSAGES: :[[@LINE-5]]:34: note: the first parameter in the range is 'A'
-// CHECK-MESSAGES: :[[@LINE-6]]:41: note: the last parameter in the range is 'B'
-// This is actually a false positive: the "passed to same function" heuristic
-// can't map the parameter index 1 to A and B because myprint() has no
-// parameters.
+#endif
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters.c
index b6c9bf4ad0c15..1d06afd85f468 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN: %check_clang_tidy -std=c99,c11,c17 -check-suffixes=,BEFORE-23 %s bugprone-easily-swappable-parameters %t \
// RUN: -config='{CheckOptions: { \
// RUN: bugprone-easily-swappable-parameters.MinimumLength: 2, \
// RUN: bugprone-easily-swappable-parameters.IgnoredParameterNames: "", \
@@ -7,7 +7,18 @@
// RUN: bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \
// RUN: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 0, \
// RUN: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold: 0 \
-// RUN: }}' -- -Wno-strict-prototypes -x c
+// RUN: }}' -- -Wno-strict-prototypes
+//
+// RUN: %check_clang_tidy -std=c23 %s bugprone-easily-swappable-parameters %t \
+// RUN: -config='{CheckOptions: { \
+// RUN: bugprone-easily-swappable-parameters.MinimumLength: 2, \
+// RUN: bugprone-easily-swappable-parameters.IgnoredParameterNames: "", \
+// RUN: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)", \
+// RUN: bugprone-easily-swappable-parameters.QualifiersMix: 0, \
+// RUN: bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \
+// RUN: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 0, \
+// RUN: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold: 0 \
+// RUN: }}' -- -Wno-strict-prototypes
#define bool _Bool
#define true 1
@@ -45,8 +56,11 @@ void pointerConversion(int *IP, long *LP) {}
void testVariadicsCall() {
int IVal = 1;
+
+#if __STDC_VERSION__ < 202311L
decl(IVal); // NO-WARN: Particular calls to "variadics" are like template
// instantiations, and we do not model them.
+#endif
variadic(IVal); // NO-WARN.
variadic(IVal, 2, 3, 4); // NO-WARN.
@@ -64,13 +78,15 @@ void taggedTypes2(struct S SVar1, struct S SVar2) {}
void wrappers(struct { int I; } I1, struct { int I; } I2) {} // NO-WARN: Distinct anonymous types.
+#if __STDC_VERSION__ < 202311L
void knr(I, J)
int I;
int J;
{}
-// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: 2 adjacent parameters of 'knr' of similar type ('int')
-// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the first parameter in the range is 'I'
-// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the last parameter in the range is 'J'
+// CHECK-MESSAGES-BEFORE-23: :[[@LINE-3]]:3: warning: 2 adjacent parameters of 'knr' of similar type ('int')
+// CHECK-MESSAGES-BEFORE-23: :[[@LINE-4]]:7: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES-BEFORE-23: :[[@LINE-4]]:7: note: the last parameter in the range is 'J'
+#endif
void boolAsWritten(bool B1, bool B2) {} // NO-WARN: The type name is ignored.
// Note that "bool" is a macro that expands to "_Bool" internally, but it is
@@ -145,7 +161,7 @@ void thisIsGettingRidiculous(MAKE_PRIMITIVE_WRAPPER(int) I1,
void macroMagic3(MAKE_LOGICAL_TYPE(char) B1, MAKE_LOGICAL_TYPE(long) B2) {}
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 2 adjacent parameters of 'macroMagic3' of similar type ('bool')
// CHECK-MESSAGES: :[[@LINE-4]]:30: note: expanded from macro 'MAKE_LOGICAL_TYPE'
-// CHECK-MESSAGES: :[[@LINE-136]]:14: note: expanded from macro 'bool'
+// CHECK-MESSAGES: :[[@LINE-141]]:14: note: expanded from macro 'bool'
// CHECK-MESSAGES: :[[@LINE-4]]:42: note: the first parameter in the range is 'B1'
// CHECK-MESSAGES: :[[@LINE-5]]:70: note: the last parameter in the range is 'B2'
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c
index a383958fbb906..b241d683b0cdc 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
#include "not-null-terminated-result-c.h"
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c
index 434cfcc0ca9d5..ea7e183b92531 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c
@@ -1,7 +1,7 @@
// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
// RUN: -config="{CheckOptions: \
// RUN: {bugprone-not-null-terminated-result.WantToUseSafeFunction: true}}" \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
#include "not-null-terminated-result-c.h"
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c
index 5a5e35ef733f6..ae430878daf21 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
#include "not-null-terminated-result-c.h"
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c
index 0628d0ca53300..94806714efc86 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
#include "not-null-terminated-result-c.h"
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c
index 4970af83bf4b6..366c1698e4f2d 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
// FIXME: Something wrong with the APInt un/signed conversion on Windows:
// in 'strncmp(str6, "string", 7);' it tries to inject '4294967302' as length.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c
index 2704dc1ee513b..bb5961f3b421e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
-// RUN: -- -std=c11 -I %S/Inputs/not-null-terminated-result
+// RUN: -- -I %S/Inputs/not-null-terminated-result
#include "not-null-terminated-result-c.h"
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c
index c7daec0870f49..a8f6f3bba20b9 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler.c
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-signal-handler %t -- -- -isystem %clang_tidy_headers
+// RUN: %check_clang_tidy -std=c99,c11,c17 -check-suffixes=,BEFORE-23 %s bugprone-signal-handler %t -- -- -isystem %clang_tidy_headers
+// RUN: %check_clang_tidy -std=c23-or-later %s bugprone-signal-handler %t -- -- -isystem %clang_tidy_headers
#include "signal.h"
#include "stdlib.h"
@@ -174,8 +175,10 @@ void test_other(void) {
signal(SIGINT, handler_signal);
signal(SIGINT, _Exit);
+#if __STDC_VERSION__ < 202311L
signal(SIGINT, other_call);
- // CHECK-NOTES: :[[@LINE-1]]:18: warning: standard function 'other_call' may not be asynchronous-safe; using it as a signal handler may be dangerous [bugprone-signal-handler]
+ // CHECK-NOTES-BEFORE-23: :[[@LINE-1]]:18: warning: standard function 'other_call' may not be asynchronous-safe; using it as a signal handler may be dangerous [bugprone-signal-handler]
+#endif
signal(SIGINT, f_extern_handler);
// CHECK-NOTES: :[[@LINE-1]]:18: warning: cannot verify that external function 'f_extern_handler' is asynchronous-safe; using it as a signal handler may be dangerous [bugprone-signal-handler]
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c
index b898071a56613..871715b22cc56 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c
@@ -1,5 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-sizeof-expression %t -- --
-// RUN: %check_clang_tidy %s bugprone-sizeof-expression %t -- -- -x c++
+// RUN: %check_clang_tidy %s bugprone-sizeof-expression %t
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-sizeof-expression %t -- -- -x c++
#ifdef __cplusplus
#define STRKWD
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c
index 0409dd6bfcaa3..a87bc84434bd7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c
@@ -5,14 +5,14 @@
// parsing and preprocessor state will not have that case.
// UNSUPPORTED: target={{.*-(ps4|ps5)}}
//
-// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K %s bugprone-unsafe-functions %t -- -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
-// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__ -U__STDC_WANT_LIB_EXT1__
-// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -D__STDC_LIB_EXT1__=1 -U__STDC_WANT_LIB_EXT1__
-// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__ -D__STDC_WANT_LIB_EXT1__=1
-// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K-CERT-ONLY %s bugprone-unsafe-functions %t -- \
+// RUN: %check_clang_tidy -std=c11-or-later -check-suffix=WITH-ANNEX-K %s bugprone-unsafe-functions %t -- -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -std=c11-or-later -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__ -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -std=c11-or-later -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -D__STDC_LIB_EXT1__=1 -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -std=c11-or-later -check-suffix=WITHOUT-ANNEX-K %s bugprone-unsafe-functions %t -- -- -U__STDC_LIB_EXT1__ -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -std=c11-or-later -check-suffix=WITH-ANNEX-K-CERT-ONLY %s bugprone-unsafe-functions %t -- \
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.ReportMoreUnsafeFunctions: false}}" \
// RUN: -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
-// RUN: %check_clang_tidy -check-suffix=WITH-NONE-ENABLED %s bugprone-unsafe-functions %t --\
+// RUN: %check_clang_tidy -std=c11-or-later -check-suffix=WITH-NONE-ENABLED %s bugprone-unsafe-functions %t --\
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.ReportDefaultFunctions: false}}" \
// RUN: -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/objc-function-naming.m b/clang-tools-extra/test/clang-tidy/checkers/google/objc-function-naming.m
index 4c204c7468256..13d00a86b3c72 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/objc-function-naming.m
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/objc-function-naming.m
@@ -8,7 +8,7 @@ static void TestImplicitFunctionDeclaration(int a) {
printf("%d", a);
}
-typedef _Bool bool;
+#define bool _Bool
static bool ispositive(int a) { return a > 0; }
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static function named 'ispositive'
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.c b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.c
index 77262c219df03..b83a09362da04 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-static-assert %t -- -- -std=c11
+// RUN: %check_clang_tidy -std=c11-or-later %s misc-static-assert %t
// RUN: clang-tidy %s -checks=-*,misc-static-assert -- -std=c99 | count 0
void abort(void) {}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c
index bde93ea219a57..e2f501c708f01 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-unused-parameters %t -- -- -Wno-strict-prototypes -xc
+// RUN: %check_clang_tidy %s misc-unused-parameters %t -- -- -Wno-strict-prototypes
// Basic removal
// =============
@@ -6,14 +6,18 @@ void a(int i) {;}
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
// CHECK-FIXES: {{^}}void a(int i) {;}{{$}}
-static void b(); // In C, forward declarations can leave out parameters.
+#if __STDC_VERSION__ < 202311L
+static void b(); // In C before C23, forward declarations can leave out parameters.
+#endif
static void b(int i) {;}
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i' is unused [misc-unused-parameters]
// CHECK-FIXES: {{^}}static void b() {;}{{$}}
// Unchanged cases
// ===============
+#if __STDC_VERSION__ < 202311L
void h(i, c, d) int i; char *c, *d; {} // Don't mess with K&R style
+#endif
// Do not warn on naked functions.
__attribute__((naked)) void nakedFunction(int a, int b) { ; }
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
index 6fb879b91e41c..d9b7ec2f7d190 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- -- -std=c23
+// RUN: %check_clang_tidy -std=c23-or-later %s modernize-use-nullptr %t
#define NULL 0
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
index f8660924cbef5..01e458e1b8d8b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
@@ -1,6 +1,5 @@
-// RUN: %check_clang_tidy %s readability-magic-numbers %t --
+// RUN: %check_clang_tidy -std=c23-or-later %s readability-magic-numbers %t
// Don't crash
_BitInt(128) A = 4533629751480627964421wb;
-// CHECK-MESSAGES: warning
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-standard-types.h b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-standard-types.h
index e1036483ee8f6..51fa9c3021348 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-standard-types.h
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-standard-types.h
@@ -50,8 +50,8 @@ typedef void* FILE; // NOLINT
#define NULL (0) // NOLINT
#ifndef __cplusplus
-typedef _Bool bool; // NOLINT
typedef __WCHAR_TYPE__ wchar_t; // NOLINT
+#define bool _Bool // NOLINT
#define true 1 // NOLINT
#define false 0 // NOLINT
#endif
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
index 11ff7dd816a44..5a4627aa49f1a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
@@ -1,8 +1,8 @@
-// RUN: %check_clang_tidy --match-partial-fixes %s readability-implicit-bool-conversion %t -- -- -std=c23
-// RUN: %check_clang_tidy -check-suffix=UPPER-CASE %s readability-implicit-bool-conversion %t -- \
+// RUN: %check_clang_tidy -std=c23-or-later --match-partial-fixes %s readability-implicit-bool-conversion %t
+// RUN: %check_clang_tidy -std=c23-or-later -check-suffix=UPPER-CASE %s readability-implicit-bool-conversion %t -- \
// RUN: -config='{CheckOptions: { \
// RUN: readability-implicit-bool-conversion.UseUpperCaseLiteralSuffix: true \
-// RUN: }}' -- -std=c23
+// RUN: }}'
#undef NULL
#define NULL 0L
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c
index db50467f3dd94..e254215f5f5d6 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s readability-non-const-parameter %t
+// RUN: %check_clang_tidy -std=c99,c11,c17 %s readability-non-const-parameter %t
static int f();
More information about the cfe-commits
mailing list