Author: Baranov Victor Date: 2026-08-04T12:40:39+03:00 New Revision: b4deecd89085c11225c428cbb27c2e44925e78d9
URL: https://github.com/llvm/llvm-project/commit/b4deecd89085c11225c428cbb27c2e44925e78d9 DIFF: https://github.com/llvm/llvm-project/commit/b4deecd89085c11225c428cbb27c2e44925e78d9.diff LOG: [clang-tidy] Add 'or-earlier' suffix to check_clang_tidy.py (#213834) Added: Modified: clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/check_clang_tidy.py Removed: ################################################################################ diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 05407c3319683..0dcf2ea1f21c7 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -94,6 +94,10 @@ Improvements to clang-query Improvements to clang-tidy -------------------------- +- Improved :program:`check_clang_tidy.py` by adding support of + ``-std=cXX-or-earlier`` values, mirroring the existing ``-std=cXX-or-later``. + New construct expands to the given standard and every earlier one. + New checks ^^^^^^^^^^ 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 7bd9647a66e89..718ae361889ce 100755 --- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -40,6 +40,10 @@ -std=c++(98|11|14|17|20)-or-later: This flag will cause multiple runs within the same check_clang_tidy execution. Make sure you don't have shared state across these runs. + + -std=c++(98|11|14|17|20)-or-earlier: + Like -or-later, but expands to the given standard and every earlier one + instead. """ import argparse @@ -459,29 +463,43 @@ def run(self) -> None: C_STANDARDS = ["c99", ("c11", "c1x"), "c17", ("c23", "c2x"), "c2y"] +def canonical_std_spelling(entry) -> str: + return entry if isinstance(entry, str) else entry[0] + + def expand_std(std: str) -> List[str]: - split_std, or_later, suffix = std.partition("-or-later") - - if or_later and suffix: - # Keep malformed -or-later spellings unchanged so clang diagnoses them. - return [std] - - if not or_later: - return [split_std] - - for standard_list in (CPP_STANDARDS, C_STANDARDS): - item = next( - ( - i - for i, v in enumerate(standard_list) - if (split_std in v if isinstance(v, (list, tuple)) else split_std == v) - ), - None, - ) - if item is not None: - return [split_std] + [ - x if isinstance(x, str) else x[0] for x in standard_list[item + 1 :] - ] + for expand_suffix, expand_later in (("-or-later", True), ("-or-earlier", False)): + split_std, matched_suffix, remainder = std.partition(expand_suffix) + + if not matched_suffix: + continue + + if remainder: + # Keep malformed -or-later/-or-earlier spellings unchanged so + # clang diagnoses them. + return [std] + + for standard_list in (CPP_STANDARDS, C_STANDARDS): + item = next( + ( + i + for i, v in enumerate(standard_list) + if ( + split_std in v + if isinstance(v, (list, tuple)) + else split_std == v + ) + ), + None, + ) + if item is not None: + if expand_later: + return [split_std] + [ + canonical_std_spelling(x) for x in standard_list[item + 1 :] + ] + return [canonical_std_spelling(x) for x in standard_list[:item]] + [ + split_std + ] return [std] @@ -526,7 +544,7 @@ def parse_arguments() -> Tuple[argparse.Namespace, List[str]]: "-std", type=csv, default=None, - help="Passed to clang. Special -or-later values are expanded.", + help="Passed to clang. Special -or-later/-or-earlier values are expanded.", ) parser.add_argument( "--match-partial-fixes", _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
