[Bug c++/82213] New: Please warn about const rvalue reference parameters [void func(const T&&);]
palves at redhat dot com
gcc-bugzilla@gcc.gnu.org
Thu Sep 14 10:09:00 GMT 2017
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.
More information about the Gcc-bugs
mailing list