1

Temporary materialization conversion is a standard conversion, see § 7.3 Standard Conversions; 7.3.4 [conv.rval]:

A prvalue of type T can be converted to an xvalue of type T. This conversion initializes a temporary object ([class.temporary]) of type T from the prvalue by evaluating the prvalue with the temporary object as its result object, and produces an xvalue denoting the temporary object. T shall be a complete type.

But why is it not mentioned in the list of standard conversion sequences?

See [conv]/1:

A standard conversion sequence is a sequence of standard conversions in the following order:

  • Zero or one conversion from the following set: lvalue-to-rvalue conversion, array-to-pointer conversion, and function-to-pointer conversion.

  • Zero or one conversion from the following set: integral promotions, floating-point promotion, integral conversions, floating-point conversions, floating-integral conversions, pointer conversions, pointer-to-member conversions, and boolean conversions.

  • Zero or one function pointer conversion.

  • Zero or one qualification conversion.

Is it because an object would have to be created either way, and therefore would have no impact on determining whether a conversion sequence is better than another?

9
  • 3
    Can you make your question self contained please? Commented Sep 2, 2019 at 17:26
  • 1
    Temporary materialization is not a "conversion" operation. So why would it be in the "standard conversion sequence" if it's not a conversion? Commented Sep 2, 2019 at 17:35
  • All relevant parts of the question should be in the question. Not behind links to external sites. Commented Sep 2, 2019 at 17:36
  • 1
    @NicolBolas The standard calls it a conversion: eel.is/c++draft/conv.rval In fact under the header standard conversions. Commented Sep 2, 2019 at 17:36
  • I think you're misunderstanding what it's saying. The conversion is from a prvalue to an xvalue. That conversion involves temporary materialization, but temporary matieralization is not the goal. Commented Sep 2, 2019 at 17:38

1 Answer 1

2

Is it because an object would have to be created either way, and therefore would have no impact on determining whether a conversion sequence is better than another?

Yes, temporary materialization is not a choice, so it's "free" and exempt from ICS ranking. It's applied when needed, see [expr.basic.lval]/7:

Whenever a prvalue appears as an operand of an operator that expects a glvalue for that operand, the temporary materialization conversion is applied to convert the expression to an xvalue.

For example, the dot-expression requires the left-hand side to be a glvalue:

struct X {
  void func(int) { }
  void func(long) { }
};

int n = 1;

X().func(n);

Here the X() prvalue must first become an xvalue (materialized) before we can proceed to .func(n), at which time ICS ranking comes into picture to decide how to invoke func(n), since there can be different conversion sequences leading to different alternatives.

Sign up to request clarification or add additional context in comments.

3 Comments

I was thinking something more like struct A {}; void f(A); void f(const A&); void g() { f(A()); } since some initialization would have to occur anyways, for any of these cases, the temporary materialization conversion need not be in conversion sequence, since some kind of object would have to be created either way.
The entire term "temporary materialization" is invented for C++17 guaranteed copy elision rules, where a prvalue evaluation can be delayed. The object is nevertheless always materialized, sooner or later. It's just, like everything in C++, specified through the horse's rear end.
So it's not in a standard conversion sequence because initialization will occur anyways

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.