Please consider the simple example as follows, where the function bar
returns an object of class A
with private destructor, and mandatory return value optimization (RVO) must take place:
class A { ~A() = default; };
A bar() { return {}; }
The code is accepted by Clang, but rejected by GCC with the error:
error: 'constexpr A::~A()' is private within this context
2 | A bar() { return {}; }
| ^
https://gcc.godbolt.org/z/q6c33absK
Which one of the compilers is right here?