I know that const
and volatile
are mentioned in the C++ specification as the "cv-qualifiers", like [basic.type.qualifier].
Now I have this code (godbolt) which doesn't compile.
#include <string>
class Dummy
{
std::string member{"test"};
public:
std::string const && foo() &&
{ return std::move(member); }
};
int main()
{
Dummy d;
std::string s = d.foo();
}
It doesn't compile because w
is an LValue and foo()
only exists for RValues. That's fine and expected.
But let's have a look at the error message:
<source>: In function 'int main()':
<source>:14:26: error: passing 'Dummy' as 'this' argument discards qualifiers [-fpermissive]
14 | std::string s = d.foo();
| ~~~~~^~
<source>:7:26: note: in call to 'const std::string&& Dummy::foo() &&'
7 | std::string const && foo() &&
|
The error message says "discards qualifiers". Thus my question: is &&
considered a qualifier, too? If it's not a qualifier, what is it then?
I can understand that the compiler would need to drop &&
to &
or to nothing in order to make it compile. So yes, it needs to discard something. But what exactly is it that it would need to drop?