Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The candidate conversion functions of directly binding reference #4443

Closed
xmh0511 opened this issue Dec 30, 2020 · 3 comments
Closed

The candidate conversion functions of directly binding reference #4443

xmh0511 opened this issue Dec 30, 2020 · 3 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Dec 30, 2020

Consider the candidate conversion function that required in section [dcl.init.ref], the candidate set is defined as:
over.match.ref#1.1.2

Let R be a set of types including.

  • “lvalue reference to cv2 T2” (when initializing an lvalue reference or an rvalue reference to function) and
  • “cv2 T2” and “rvalue reference to cv2 T2” (when initializing an rvalue reference or an lvalue reference to function)

The wording in the parenthesis of the second bullet looks like we don't consider these conversion functions of return type “cv2 T2” and “rvalue reference to cv2 T2” as candidate functions when the reference be initialized is an lvalue reference to a const-qualified object type.

struct S{
  int i = 0;
  operator int&&(){ //#1
    return (int&&)i;
  }
};
int main(){
  int const& rf = S{};
}

Isn't #1 not a candidate function for initializing rf? I think the wording should be reworded.
And forming the conversion function candidate sets should be separated into two phases. The intent of dcl.init.ref#5.1.2 is considering all conversion functions whose return type are lvalue reference.
Instead, the intent of dcl.init.ref#5.3.2 is considering all conversion functions whose return type are “cv2 T2” and “rvalue reference to cv2 T2” when the initialized reference is rvalue reference or lvalue reference to const-qualified type.

@jensmaurer
Copy link
Member

The wording in the parenthesis of the second bullet looks like we don't consider these conversion functions of return type “cv2 T2” and “rvalue reference to cv2 T2” as candidate functions when the reference be initialized is an lvalue reference to a const-qualified object type.

Yes, because that's not direct reference binding. (A temporary will be materialized.)

@xmh0511
Copy link
Contributor Author

xmh0511 commented Dec 30, 2020

The wording in the parenthesis of the second bullet looks like we don't consider these conversion functions of return type “cv2 T2” and “rvalue reference to cv2 T2” as candidate functions when the reference be initialized is an lvalue reference to a const-qualified object type.

Yes, because that's not direct reference binding. (A temporary will be materialized.)

Doesn't temporary materialization conversion apply to when the conversion function's return type is cv T and the reference be initialized is an rvalue reference? why exclude lvalue reference to const-qualified type?

As said in: If the converted initializer is a prvalue, its type T4 is adjusted to type “cv1 T4” ([conv.qual]) and the temporary materialization conversion is applied. In any case, the reference is bound to the resulting glvalue (or to an appropriate base class subobject).

Or, Is that just the intent of the standard to avoid to view the binding lvalue reference to a const-qualified type to an rvalue as directly binding? which should undergo dcl.init.ref#5.4.1 or dcl.init.ref#5.4.2. which are the so-called exceptions said in this rule: In all cases except the last (i.e., implicitly converting the initializer expression to the referenced type), the reference is said to bind directly to the initializer expression.

@jensmaurer
Copy link
Member

It looks like we consider initializing an rvalue-ref from a prvalue a "direct reference binding", for better or worse.

In any case, I'm not seeing anything that could be fixed editorially here (i.e. if we change something, it will have effects on the meaning of the standard).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants