Questions tagged [lvalue-to-rvalue]

Use this tag for lvalue to rvalue conversion questions

C++ expression is either an lvalue or an rvalue.

A lvalue refers to an object that persists beyond a single expression. You can think of an lvalue as an object that has a name. All variables, including nonmodifiable (const) variables, are lvalues.

A rvalue is a temporary value that does not persist beyond the expression that uses it.

Lvalues and Rvalues: https://msdn.microsoft.com/en-us/library/f90831hc.aspx

60 questions
2
votes
2 answers

Using uninitialized variable without invoking undefined behavior

From 6.3.2.1 (emphasis mine) If the lvalue designates an object of automatic storage duration that could have been declared with the register storage class (never had its address taken), and that object is uninitialized (not declared with an…
izac89
  • 3,790
  • 7
  • 30
  • 46
2
votes
1 answer

C++ pass vector (lvalue to rvalue)

Lets say you have 2 vectors passed to a function as lvalue references. Later you realize, you can use recursion and pass slices of these vectors using their iterators. Would it be an appropriate strategy if I go ahead and write some util function…
user2376997
  • 501
  • 6
  • 22
2
votes
1 answer

What are the rules about using an rvalue reference on the left side of an equals sign?

So I've been learning about rvalues and rvalue references and have run into some code while experimenting that I can't wrap my head around the errors of. int&& test1(int& t) { return static_cast(t); } std::string&& test2(std::string&…
2
votes
1 answer

What is the difference in atomic_load() and assignment?

I am working on a project that deals with lots of atomic operations. Till now I didn’t knew about atomic_load() and was only relying on assignment operator to get value of an atomic type and I haven’t seen an error except of so much of testing.…
Mihir Luthra
  • 6,059
  • 3
  • 14
  • 39
2
votes
2 answers

Lvalue to rvalue conversion not performed

The following function returns an rvalue: int foo() { int x = 42; return x; // x is converted to prvalue } Clang's AST also shows the conversion: `-FunctionDecl line:1:5 foo 'int ()' `-CompoundStmt
wally
  • 10,717
  • 5
  • 39
  • 72
2
votes
1 answer

Lvalue to rvalue conversion with integer pointer

If I read implicit conversions correctly: Lvalue to rvalue conversion A glvalue of any non-function, non-array type T can be implicitly converted to a prvalue of the same type. [..] Unless encountered in unevaluated context (in an operand of…
Dean
  • 6,610
  • 6
  • 40
  • 90
2
votes
2 answers

C++11 ambiguous error with two operators (one lvalue second rvalue)

UPDATE at the bottom. I want make void tree::operator = ( tree t ) to use the rvalue one.(in this case, in general I want to handle them differently because of efficiency) I've coded it, used std::move to ensure it will use rvalue, but compiler is…
Marqin
  • 1,096
  • 8
  • 17
1
vote
1 answer

Lvalue-to-rvalue conversion C++

I read about Lvalue-to-rvalue conversion and Comparison operators This quote from Comparison operators : after the application of the lvalue-to-rvalue, array-to-pointer and function-to-pointer standard conversions. The comparison is deprecated…
f877576
  • 447
  • 2
  • 7
1
vote
0 answers

rvalue and lvalue of std::string

i ran the code as shown and i am confused as to why a+b is a rvalue. From what i know, rvalue should only have a data or address and in such a case std::string should be a lvalue isn't it? void foo(const std::string&& input){ std::cout<<"RVALUE…
Iberico
  • 162
  • 2
  • 15
1
vote
1 answer

How do I pass a temporary object as a non-const reference into a member function?

We are creating a class designed to send information out from the current module (the specifics are not relevant to this question). An object of this type is created and populated with a portion of the data that needs to be sent, and then passed…
1
vote
1 answer

C2664 cannot convert to && value

The compiler wants my lvalue to be a rvalue reference and I dont see why. My questions are: Why is "dataLen" const, even though it was declared non const and the lambda is told to catch by reference as default? Why does the compiler try to convert…
Natulux
  • 187
  • 1
  • 1
  • 11
1
vote
1 answer

Clang vs G++ lvalue to rvalue conversion

The question related to this one. By tracing slt_pair. h and move. h, it's seems that the difference between Clang and G++ is internally. I have tried to simulate the assignment of the object (pair.first) as same as the implementation of…
4.Pi.n
  • 1,151
  • 6
  • 15
1
vote
2 answers

Safety of auto when std::move ing from a returned reference of a value

I need some reassurance about whenever, assigning or list initializing an auto typed named variable, with A a std::move()ed returned reference to a variable B a returned reference to a variable where after the expression, the origin gets out of…
Superlokkus
  • 4,731
  • 1
  • 25
  • 57
1
vote
2 answers

When a function takes an rvalue reference, what is the type of that variable within the function?

This is a question of terminology. If I have this: #include void g(std::vector&& arg); void f0(std::vector&& v) { static_assert(std::is_same&&>::value); // Looks like v is an rvalue reference. …
Ben
  • 9,184
  • 1
  • 43
  • 56
1
vote
3 answers

regarding lvalue-to-rvalue conversion

"lvalue-to-rvalue conversion is not done on the operand of the unary & operator." May I know what it meant for >Can any one explain ..It Please Ex: int a[]={1,5}; int* x=&a;
BE Student