Link initialization and direct indirect binding

Consider the following case

struct A { operator int(); }; int &&x = A(); 

The spectrum says in http://eel.is/c++draft/dcl.init.ref#5 about whether link binding is direct or indirect

In all cases except the last (i.e., creating and initializing the temporary from the initializer expression), the link refers directly to the initializer expression.

The above case does not coincide with the last, but the second last.

If T1 or T2 is a class type, and T1 is not associated with a binding to T2, user-defined conversions are taken into account ... The result of calling the transform function, as described for a minor copy-initialization, is then used to directly initialize the link.

Therefore, binding A() to a link is an indirect binding. To continue, we will again include in reference initialization, now with a prvalue of type int , trying to initialize int&& . Now we are done with the last bullet, which means direct binding.

So what can we say about link binding ... does it link directly or indirectly? Does it do both, depending on what expression you think (initializer expression and the result of calling the transform function)?

In our case, in particular, paragraphs are said to bind directly to the initializer expression and indirectly bind to the result of the transformation in the initializer expression. However, in the chapter on overloading http://eel.is/c++draft/over.ics.ref we distinguish only

  • When a reference type parameter is directly associated ([dcl.init.ref]) with an argument expression,
  • If the parameter is bound directly to the result of applying the transform function to the argument expression,
  • If the reference type parameter is not directly related to the argument expression,

For a case like

 void f(int &&); f(A()); 

Case 1 applies, but I'm sure it is not intended to be used. I feel that โ€œin all cases except the last oneโ€, not only the case of creating a temporary case is meant, but also the second last bullet or, alternatively, the whole branch โ€œOtherwise:โ€, which contains two bullets (i.e. โ€œ the latter "refers to another level in the bullet hierarchy). Could you clarify?

+1
source share

Source: https://habr.com/ru/post/1236506/


All Articles