In my attempt to learn C++'s const correctness in combination with move semantics, I ended up with the following code.
MRE:
#include <iostream>
class ThisReference
{
public:
void f() const && { std::cout << "f() const &&\n"; }
};
int main()
{
(const ThisReference){}.f();
}
Godbolt [a little bit longer with all method candidates]
That code compiles with GCC and I thought I understood what it means, i.e.:
(const ThisReference)
defines the type. I wanted it to be const, so I put that into parens.{}
does the initialization of that type; creates an object.f()
calls the method;
ends the statement
Eventually I put that code into Visual Studio and it didn't compile. The error message is
error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax
I have 2 questions about my code.
- Which non-standard GCC feature am I using here and how would I turn it off?
- Something in my thinking is probably wrong. What is wrong?