Value category of defaulted assignment operator - lvalue or rvalue? (clang vs gcc)

366 Views Asked by At

Consider the following code:

struct S 
{ 
    S& operator=(const S&) = default;
};

int main()
{
    &(S() = S());
}

GCC (trunk) complains with:

  error: taking address of rvalue [-fpermissive]
    8 |     &(S() = S());
      |      ~~~~~^~~~~~

I found the above error surprising, as I would expect an S& return type to produce an lvalue expression. Clang (trunk), on the other hand, accepts the code without any error or warning.

live on godbolt.org

  • What compiler is correct here?

  • Is S() = S() an rvalue or an lvalue?

0

There are 0 best solutions below