[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast<T&>`. (PR #99477)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 22 02:41:55 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 7e6a73959ae97b1f9476a90290a492ba90cb950d 43b51e07cbd5d575a82f345913cf663b988907c6 --extensions cpp -- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-casts.cpp clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index 3529f82acf..2a027a0190 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -26,7 +26,8 @@ AST_MATCHER_P(QualType, possiblyPackExpansionOf,
 }
 
 AST_MATCHER_P(ParmVarDecl, isForwardingReferenceType,
-              ast_matchers::internal::Matcher<RValueReferenceType>, InnerMatcher) {
+              ast_matchers::internal::Matcher<RValueReferenceType>,
+              InnerMatcher) {
   ast_matchers::internal::Matcher<QualType> Inner = possiblyPackExpansionOf(
       qualType(rValueReferenceType(InnerMatcher),
                references(templateTypeParmType(
@@ -130,17 +131,13 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
       unless(anyOf(hasAncestor(typeLoc()),
                    hasAncestor(expr(hasUnevaluatedContext())))));
 
-  auto StaticCast = Options.get("IgnoreStaticCasts", false)
-                        ? cxxStaticCastExpr(hasDestinationType(
-        lValueReferenceType(
-            pointee(
-                type(equalsBoundNode("qtype"))
-            )
-        )
-    ),
-                                            hasSourceExpression(
-                              declRefExpr(to(equalsBoundNode("param")))))
-                        : cxxStaticCastExpr(unless(anything()));
+  auto StaticCast =
+      Options.get("IgnoreStaticCasts", false)
+          ? cxxStaticCastExpr(
+                hasDestinationType(lValueReferenceType(
+                    pointee(type(equalsBoundNode("qtype"))))),
+                hasSourceExpression(declRefExpr(to(equalsBoundNode("param")))))
+          : cxxStaticCastExpr(unless(anything()));
 
   Finder->addMatcher(
       parmVarDecl(

``````````

</details>


https://github.com/llvm/llvm-project/pull/99477


More information about the cfe-commits mailing list