difference between ctor{} and {} when returning non-movable, non-copyable object

return {} uses an empty initialiser list to initialise the return value, using the default constructor.

return test{} creates a temporary using the default constructor, then uses that to initialise the return value using a move or copy constructor. You have deleted those constructors, so that can't be done.

In practice, the copy or move will be elided so that both have the same effect - but the second still requires an accessible constructor, even if it's not actually used.

Tags:

C++

C++11