[clang-tools-extra] [clang-tidy] Add `-std` argument in `check_clang_tidy.py` for C files (PR #150791)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 20 15:55:54 PDT 2025
================
@@ -374,15 +373,23 @@ 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(
"--match-partial-fixes",
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"
----------------
localspook wrote:
In those cases, the tests will break if they don't specify `-std`. The script will try to invoke something like `clang foo.cxx -std=c99`, which will error out, saying that you can't specify a C standard for a C++ file. Same thing with C++ `.h` files, but note that in that case, users already have to specify `-x c++`, because clang won't understand that this is a C++ file otherwise. We'll need to keep the list updated if we want the default behaviour to Just Work.
(Also, I think my PR description was a bit misleading, so I want to be clear; `-std` being ignored is a problem that applies not just to C, but to any file with an extension other than `.cpp`, `.hpp`, or `.mm`.)
https://github.com/llvm/llvm-project/pull/150791
More information about the cfe-commits
mailing list