[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

Chris Cotter via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 20 21:29:58 PST 2023


ccotter added inline comments.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp:45
+template <typename T>
+void never_moves_param_template(Obj&& o, T t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
----------------
ccotter wrote:
> ccotter wrote:
> > carlosgalvezp wrote:
> > > Could we add something like this too?
> > > 
> > > ```
> > > template <typename T>
> > > struct Foo
> > > {
> > >   void never_moves(T&& t) {}
> > > };
> > > ```
> > > 
> > > Here `t` is not a universal reference so the check should warn.
> > Done in the `AClassTemplate::never_moves` test.
> @carlosgalvezp Note I've changed the check to not flag `never_moves` based on more recent discussion. I do think this code should flag, although I'm a little torn. If `Foo` constrains `T` to be a reference, then `Foo<Obj&>::never_moves` is "OK", although I think it's still confusing as `never_moves` could instead accept `T&`.
> 
> I'll need to rethink this a bit, but I've never the test in place with a `FIXME` and brief comment explaining the situation.
That should read "I've left the test in place"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569



More information about the cfe-commits mailing list