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

Reference Initialization: function lvalue covered by two cases #2882

Closed
h0nzZik opened this issue May 13, 2019 · 1 comment
Closed

Reference Initialization: function lvalue covered by two cases #2882

h0nzZik opened this issue May 13, 2019 · 1 comment

Comments

@h0nzZik
Copy link

h0nzZik commented May 13, 2019

The section dcl.init.ref of the C++ standard contains rules for initialization of references. However, the case when the initializer is a function lvalue seem to be covered twice: first time implicitly in [dcl.init.ref]/5.1.1:

If [...] the initializer expression
is an lvalue
(but is not a bit-field), and “cv1 T1” is reference-compatible with “cv2 T2”, or [...]

and second time explicitly in [dcl.init.ref]/5.3.1:

Otherwise, if the initializer expression is an rvalue (but not a bit-field) or function lvalue and “cv1 T1” is reference-compatible with “cv2 T2”, or [...].

Moreover, the second instance is hidden behind otherwise, and so cannot apply to anything.

is this intentional?

@cpplearner
Copy link
Contributor

I think the intent is to permit both

void f();
decltype(f)& lref = f; // [dcl.init.ref]/(5.1.1)

and

decltype(f)&& rref = f; // [dcl.init.ref]/(5.3.1)

Note that std::move(f) is also a function lvalue.

@h0nzZik h0nzZik closed this as completed May 15, 2019
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