5
votes

I encountered the sentence, "Even when the creation of the temporary object is unevaluated", in the standard 12.2 and I do not get what they mean.

So I read about expressions but I still do not get what they mean that the they meant by that. The reason, I suppose, is that I had a hard time trying to take their definition of unevaluated expressions and apply it the the quotation stated above.

So could anybody please tell me what they mean by "Even when the creation of the temporary object is unevaluated"?

The context:

Temporaries of class type are created in various contexts: binding a reference to a prvalue (8.5.3), returning a prvalue (6.6.3), a conversion that creates a prvalue (4.1, 5.2.9, 5.2.11, 5.4), throwing an exception (15.1), entering a handler (15.3), and in some initializations (8.5). [ Note: The lifetime of exception objects is described in 15.1. — end note ] Even when the creation of the temporary object is unevaluated (Clause 5) or otherwise avoided (12.8), all the semantic restrictions shall be respected as if the temporary object had been created and later destroyed. [ Note: even if there is no call to the destructor or copy/move constructor, all the semantic restrictions, such as accessibility (Clause 11) and whether the function is deleted (8.4.3), shall be satisfied. However, in the special case of a function call used as the operand of a decltype-specifier (5.2.2), no temporary is introduced, so the foregoing does not apply to the prvalue of any such function call. — end note ]

1
Could you probably cite a bit more in order to give us a context?idmean
@idmean, of course. Let me updateuser8221510
sizeof(T()) // requires T is default constructible and destructiblecpplearner
@cpplearner That was what I was thinking but the big three all compile without issue. (example)NathanOliver

1 Answers

6
votes

There are certain contexts where you can type an expression that doesn't actually get executed at runtime. The arguments of sizeof and decltype, for example, don't actually get executed. They exist solely so that the compiler will compute the type of what the result would have been.

These contexts are called "unevaluated contexts". That's what it is talking about. And it's saying that, even in an unevaluated context, an expression that constructs an object still has to be a valid form of object initialization.