https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82213

            Bug ID: 82213
           Summary: Please warn about const rvalue reference parameters
                    [void func(const T&&);]
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: palves at redhat dot com
  Target Milestone: ---

It'd be nice if GCC would warn about const rvalue reference
parameters.

AFAIK, there's no good use for such parameters, and they'll usually lead 
to a silent pessimization when you try to move from the passed in
temporary object:

 void func (const std::vector<int> &&vec)
 {
   // does not actually move.  silently copies instead ...
   std::vector<int> vec2 = std::move (vec); 

   // ... because the above called the 'vector(const vector &)'
   // overload,  instead of 'vector(vector &&)'.
 }

See <https://sourceware.org/ml/gdb-patches/2017-09/msg00371.html> for a
case just like the above.

The only good use of 'const T &&' parameters that I'm aware of
is to delete overloads, like:

  void func(const T &);
  void func(const T &&) = delete;

... so that const rvalues don't use the const T& overload.  E.g., std::ref.

So I think it'd be nice to warn about const rvalue ref parameters 
of non-deleted functions.

Reply via email to