One of the comment in C++11 for rvalue references is incorrect
See original GitHub issueThe collection of c++ features is really good. While going through c++11.md, I found one wrong comment.
“int&& xr2 = 0; // xr2
is an lvalue of type int&&
– binds to the rvalue temporary, 0
”
Here xr2 should be rvalue reference as there is no type deduction.
Kindly look into this.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Rvalue Reference in Type Deduction in C++11 - Stack Overflow
The only question that is to answer is why T& leads to T& and not T (as it would in "normal" type deduction)....
Read more >C++ Style Guide: Incorrect information about rvalue references
Rvalue references are a type of reference that can only bind to temporary objects. This is only partially correct.
Read more >C++11/C++14 5. rvalue Reference and Move Semantics - 2020
The C++11 Standard introduces rvalue references which bind only to rvalues. They are declared with two ampersands rather than one ampersand:
Read more >C++ rvalue references and move semantics for beginners
The first operation is wrong: it's an invalid initialization of non-const reference of type int& from an rvalue of type int . The...
Read more >lvalues references and rvalues references in C++ with Examples
Prerequisites: lvalue and rvalue in C++, References in C++ “l-value” refers to a memory location that identifies an object. “r-value” refers ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @AnthonyCalandra ,
Thank you for clarifying. My interpretation of your statement was incorrect, I thought you are referring xr2 as lvalue reference but after reading carefully, I understood.
Hi @gulipalli123 ,
xr2
is absolutely an rvalue reference – there’s no doubt about it, I agree. 😃 However, because the rvalue reference has a name (the name of the variable isxr2
), it will behave as an lvalue, which is what the comment tries to make clear. There is a distinction between what the value category the reference binds to, and what the variable’s value category is itself.To help show you the above explanation in a code example, I have a small one here I want you to try running: https://godbolt.org/z/TvWYvP3aY Notice there are no universal references here, just an lvalue reference and an rvalue reference. What does it print and why?