[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 15 08:27:56 PST 2023


njames93 added a comment.

Just a few more points then it should be good to land



================
Comment at: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp:181-190
+
+  // Detect redundant 'c_str()' calls in parameters passed to std::print and
+  // std::format.
+  Finder->addMatcher(
+      traverse(
+          TK_AsIs,
+          callExpr(
----------------
Can this be wrapped in a check to make sure it only runs in c++20

Likewise `::std::print` is only c++23, so maybe:
```lang=c++
getLangOpts().CPlusPlus2B ? hasAnyName("::std::print", "::std::format") : hasAnyName("::std::format")
```


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp:1
-// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t
+// RUN: %check_clang_tidy -std=c++20 %s readability-redundant-string-cstr %t
 
----------------
We shouldn't be removing tests from older language standards
Can all the changes made to the file be moved into a new file `redundant-string-cstr-cpp20.cpp`
Would likely either need to create a second file for c++23 or make use of the check-suffix to run the tests for std::print


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143342/new/

https://reviews.llvm.org/D143342



More information about the cfe-commits mailing list