question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

One of the comment in C++11 for rvalue references is incorrect

See original GitHub issue

The 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gulipalli123commented, Mar 13, 2022

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.

0reactions
AnthonyCalandracommented, Mar 12, 2022

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 is xr2), 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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found