With guaranteed copy elision, why does the class need to be fully defined?

  • A+

A followup to this post. Consider the following:

class C; C foo(); 

That is a pair of valid declarations. C doesn't need to be fully defined when merely declaring a function. But if we were to add the following function:

class C; C foo(); inline C bar() { return foo(); } 

Then suddenly C needs to be a fully defined type. But with guaranteed copy elision, none of its members are required. There's no copying or even a move, the value is initialized elsewhere, and destroyed only in the context of the caller (to bar).

So why? What in the standard prohibits it?


The rule lies in [basic.lval]/9:

Unless otherwise indicated ([dcl.type.simple]), a prvalue shall always have complete type or the void type; ...


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: