5

[basic.execution] p5 sentence 2 states:

If a language construct is defined to produce an implicit call of a function, a use of the language construct is considered to be an expression for the purposes of this definition.

However, the intent of this sentence is not immediately clear. My best guess is that it is here in order to ensure proper sequencing and to make sure that temporaries are not destroyed before any implicit function calls complete, however, I cannot see a situation where this would apply and change the meaning of some code. For example:

struct S { };
const S& f() { return {}; }

Here, the return statement would be considered an expression, and the operand {} would also be considered an expression, and therefore a subexpression of the return statement. Is this the intent of the sentence? Where else would this apply and have a meaningful effect?

xskxzr
  • 12,442
  • 12
  • 37
  • 77
Krystian S
  • 1,586
  • 7
  • 23
  • 1
    This sentence appears since some very old version of the standard. In that version, there is a note saying this sentence applies for initializers, which is deleted by [issue 392](http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#392), and is covered by [\[intro.execution\]/5.4](http://eel.is/c++draft/basic.exec#intro.execution-5.4) in the current version. I don't know if this sentence applies for the `return` statement, since there is already [a rule](http://eel.is/c++draft/stmt.return#3) handling such cases. – xskxzr Aug 12 '19 at 08:33
  • By the way, there is no constructor called in your example, so this sentence does not apply anyway. You may consider using `struct S {S() {}};` instead. – xskxzr Aug 12 '19 at 08:35
  • In C++98 it was simply (§1.9.12) "*A full-expression is an expression that is not a subexpression of another expression. If a language construct is defined to produce an implicit call of a function, a use of the language construct is considered to be an expression for the purposes of this definition.*". It basically means anything that calls anything gets life-extended to the outermost *full-expression*. – rustyx Aug 12 '19 at 08:54
  • @xskxzr What you linked about return statements only defines the sequencing for the destruction of temporaries and variables. Also, good catch on it being an aggregate. I've figured it out since I posted this question. – Krystian S Aug 12 '19 at 14:02

1 Answers1

2

The key phrase is "in the context of this definition", i.e. the definition of full-expression.

It's just saying that the rules of a full-expression (e.g. temporary lifetime) will also apply for the entirety of your return statement, even though it's not otherwise enumerated in the list of things that constitute a full-expression.

And that's because it involves an implicit function call (a ctor call); if it didn't, then the point would be moot.

It doesn't "change the meaning" of any code.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055