[PATCH] D154999: [clang-tidy] Add bugprone-std-forward-type-mismatch check

Chris Cotter via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 3 15:29:51 PDT 2023


ccotter added inline comments.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/std-forward-type-mismatch.rst:18
+    doSomething(std::forward<Derived&>(base)); // Incorrect usage
+    doSomething(static_cast<Derived&>(base)); // Suggested usage
+  }
----------------
How confident are we to suggest a fixit to use `static_cast`? Although equivalent, the code could be incorrect to begin with and merit manual review to decide what the correct cast really should be.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone/std-forward-type-mismatch.cpp:116
+void testPartialTemplateBad(WrapperEx<T> value) {
+  test(std::forward<Wrapper<T>>(value));
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: using 'std::forward' for type conversions from 'WrapperEx<T>' to 'Wrapper<T>' is not recommended here, use 'static_cast' instead
----------------
Does this check work if `testPartialTemplateBad` is not instantiated?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154999



More information about the cfe-commits mailing list