[clang-tools-extra] [clang-tidy] Fix some false positive in bugprone-move-forwarding-reference (PR #191435)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 10 22:42:38 PDT 2026
================
@@ -80,13 +88,16 @@ void MoveForwardingReferenceCheck::registerMatchers(MatchFinder *Finder) {
.bind("parm-var");
Finder->addMatcher(
- callExpr(callee(unresolvedLookupExpr(
- hasAnyDeclaration(namedDecl(
- hasUnderlyingDecl(hasName("::std::move")))))
- .bind("lookup")),
- argumentCountIs(1),
- hasArgument(0, ignoringParenImpCasts(declRefExpr(
- to(ForwardingReferenceParmMatcher)))))
+ callExpr(
+ callee(unresolvedLookupExpr(
+ hasAnyDeclaration(
+ namedDecl(hasUnderlyingDecl(hasName("::std::move")))))
+ .bind("lookup")),
+ argumentCountIs(1),
+ hasArgument(0, ignoringParenImpCasts(declRefExpr(
+ to(ForwardingReferenceParmMatcher),
+ // FIXME: allow capture by reference
----------------
serge-sans-paille wrote:
Consider this:
```
template<class T> void foo(T&& t) {
[&t]() {
bar(std::move(t));
}();
}
```
if `foo` is called with an l-value, this example moves the reference content, the intent was probably
```
template<class T> void foo(T&& t) {
[&t]() {
bar(std::forward<T>(t));
}();
}
```
https://github.com/llvm/llvm-project/pull/191435
More information about the cfe-commits
mailing list