GCC 7.2 and Clang 5.0 disagree in this case:
struct A; A foo(); struct A { static void bar() { foo(); } private: ~A()=default; }; A foo() { return {};
This behavior is part of the "C ++ 17 Guaranteed (elite copy and not associated with RVO or NRVO)."
GCC does not compile this code, but Clang does. Which one is wrong?
Perhaps this paragraph suggests that the Clang bot and GCC are standard [class.temporary]:
When an object of class X is transferred or returned from a function, if each constructor of the copy moves the constructor and destructor of X either trivial or deleted, and X has at least one non-deleted copy or move to the constructor, implementations are allowed to create a temporary object to store the function parameter or result object . The temporary object is created from the function argument or return value, respectively, and the function parameter or return object is initialized as if using an unused trivial constructor to copy the temporary one (even if this constructor is not available or will not be selected using overload permission to perform copying or moving the object). [Note. This latitude is provided to allow objects of type class transferred or returned from functions in registers. - final note]
source share