a non-const reference may only be bound to an lvalue. The literal 0 is still a poor choice for its default value, considering that 0 is an int, and your type is. a non-const reference may only be bound to an lvalue

 
 The literal 0 is still a poor choice for its default value, considering that 0 is an int, and your type isa non-const reference may only be bound to an lvalue  And plus more, in this case if I called

thanks in advance, George. A function lvalue; If an rvalue reference or a non-volatile const lvalue reference r to type T is to be initialized by the expression e, and T is reference-compatible with U, reference r can be initialized by expression e and bound directly toe or a base class subobject of e unless T is an inaccessible or ambiguous base class of U. The foo () function accepts a non-const lvalue reference as an argument, which implies one can modify (read/write) the supplied parameter. Share. The type of such a reference must be a const qualified lvalue reference or a rvalue references. Only const lvalue references (in C++98 and C++11) or rvalue references (in C++11 only) can. U is a class type. I am still studying what is the reason in essence in compiler why a non-const reference can not be binded to a rvalue. -1. Otherwise, the reference shall be an lvalue reference to a non-volatile const type (i. The version with const Integer & works as const lvalue references can be bound to both lvalues and rvalues. yet you can still change the data x by modifying x. The Standard says no. But in your case the operands are different category (123 is a prvalue, a is an lvalue). Anything that is capable of returning a constant expression or value. Improve this answer. Since the temporary B that's returned by source () is not. Hence, values bound to an rvalue reference can be moved from (not. 5. Non-compliant compilers might allow a non-const or volatile lvalue reference to be bound to an rvalue. Let's look at std::vector for example: reference at( size_type pos ); const_reference at( size_type pos ) const; Would you look at that. r can be bound to the conversion result of e or a base class of e if the following conditions are satisfied. The pre-C++ origin of the terms "lvalue" and "rvalue" might be related to "left" and "right" side of assignment, but that meaning is only applicable in a small subset of the C++ language. It's the first const that I'm unsure of. Non-const reference may only be bound to an lvalue. Thus, the standard allows all types. They could also bind to rvalues but only when the. My understanding is that this is largely to avoid breaking several enormous legacy codebases that rely on this "extension. e. Saturday, December 15, 2007 4:49 AM. (non const) lvalue reference and rvalue that also means that you can convert the rvalue into an lvalue and therefore. e. You can also simplify the return expression, and make the method const, since comparing two objects should not change either of them: bool String::operator< (const String & obj) const { return strcmp (*this, obj) < 0; } although I am not sure strcmp can deal with two. C++ does not give that feature to non-const references: A function lvalue; If an rvalue reference or a non-volatile const lvalue reference r to type T is to be initialized by the expression e, and T is reference-compatible with U, reference r can be initialized by expression e and bound directly to e or a base class subobject of e unless T is an inaccessible or ambiguous base class of U. Unless an object is created in the read-only section of a program, it is open for modifiction without adverse consequences. Your declaration of a is a non-const lvalue reference,. Let's look at std::vector for example: reference at( size_type pos ); const_reference at( size_type pos ) const; Would you look at that. const char*&). Potentially related articles: Overload resolution between object, rvalue reference, const reference; std::begin and R-values; For a STL container C, std::begin(C) and similar access functions including std::data(C) (since C++17) are supposed to have the same behavior of C::begin() and the other corresponding C's methods. Consider the following: Products & extensions for Visual Studio. and forwards messages that it receives to that object. The temporary unsigned int could be bound to lvalue-reference to const (i. You can also simplify the return expression, and make the method const, since comparing two objects should not change either of them: bool String::operator< (const String & obj) const { return strcmp (*this, obj) < 0; } although I am not sure strcmp can deal with two. And until now we've only touched what already used to happen in C++98. aspx. 11. Value categories pertain to expressions, not objects. So, despite your extra const in your reference type the language still requires it to be bound directly to i. i have a player class in which i have a function to return a SDL_Rect for the dimensions and the position of my player object: SDL_Rect Player::pos () { return SDL_Rect { mPosX, mPosY, PLAYER_WIDTH, PLAYER_HEIGHT }; } i get the error: "initial value of. g. decltype(fun()) b=1;Exception as noted by T. An lvalue reference is a reference to an object that has a distinct memory address and can be modified. Pass by reference can only accept modifiable lvalue arguments. Otherwise. Therefore it makes sense that they are mutable. However, you don't have double && in your code, you have U && for a deduced U. Your code has two problems. A modifiable lvalue is any lvalue expression of complete, non-array type which is not const-qualified, and, if it's a struct/union, has no members that are const-qualified, recursively. int* and void* are different types; you can't bind a int* to reference to void* directly. So you want x to be either an. x, a. The reason for this is mostly convenience: It. Apr 13, 2017 at 13:00. Lifetime is extended at most once, when first binding to a reference that is not a function parameter, return value, or part of new initialization or parenthesized aggregate initialization and if the expression between the temporary materialization and. g. However, lvalue references to const forbid any change to the object and thus you may bind them to an rvalue. e. @acannon828 Okay, but then you'd be modifying the pointer that is internal to World. This example is very similar to the previous one, except the temporary object is non-const this time. The standard specifies such behavior in §8. an rvalue could bind to a non-const lvalue reference, then potentially many modifications could be done that would eventually be discarded (since an rvalue is temporary), this being useless. 1. — Otherwise, the reference shall be an lvalue reference to a non-volatile const type (i. Only const lvalue references (and rvalue references) may be bound to an object accessed through an rvalue expression. We don't know which byte should be passed. Actor & actor = get_actor_ref_from_ped (PLAYER::PLAYER_PED_ID ()); ^^^^^^^ reference. rvalue Reference Cannot Bind to a Named lvalue. 0f, c); The other similar calls need to be fixed too. All (lvalue, rvalue, const, non-const) -> const lvalue. ii. and not. The most likely explanation is that the programmer meant to pass by const reference and just forgot the const. warning C4239: nonstandard extension used: 'initializing': conversion from 'A' to 'A &' note: A non-const reference may only be bound to an lvalue warning C4239: nonstandard extension used: 'initializing': conversion from 'A' to 'A &' note: A non-const reference may only be bound to an lvalue On the other hand lvalue references to const forbids any change to the object they reference and thus you may bind them to a rvalue. Saturday, December 15, 2007 4:49 AM. The parameter of the function is an lvalue reference to non-const, and such references cannot be bound to rvalues 1. e. C++/SDL "initial value of reference to a non-const must be an lvalue". const int x = 0; int&& r = x; Here, we don't have an exact match in types: the reference wants to bind to an int, but the initializer expression has type const int. (2023/4/18 現在) 理由は引数の型が non-const reference で. @YueZhou Function lvalues may be bound to rvalue references. 6 — Pass by const lvalue reference. Why can't I bind an Rvalue to a non-const Lvalue reference? C++ does not allow binding Rvalues to non-const Lvalue references because Lvalue references can modify the object they are bound to, and Rvalues. There is no need for references. . initial value of reference to non-const must be an lvalue when calling a function. What I have seen however is that you can bind an rvalue to an rvalue reference and since a named rvalue reference is inherently an lvalue, you can bind it to an lvalue reference. This operator is trying to return an lvalue reference to a temporary created upon returning from the function: mat2& operator /= ( const GLfloat s. 1 Answer. C4239: nonstandard extension used : 'default argument' : conversion from 'QMap<QString,QVariant>' to 'QVariantMap &' A non-const reference may only be bound to an lvalue. However, when you use a const reference to a non-const object, you are asking the compiler to not let you modify the object through that particular. They can bind to const lvalue-references because then a promise has been made. push_back (std::move (obj)); } If caller passes an lvalue, then there is a copy (into the parameter) and a move (into the vector). References to non-pointer values make more sense. Within the body of a non-static member function of X, any id-expression e (e. So how to solve that. With /W4 you'd see this: warning C4239: nonstandard extension used : 'initializing' : conversion from 'Foo' to 'Foo &' 1> A non-const reference may only be bound to an lvalue Specifically, MSVC 2013 will give a warning of "mysourcefile. You can change the parameter type to const char* in or const char* const & in if in won't be modified in UTF8toWide() , or use a named variable instead. It is a name of a reference, and references refer to objects. Without rvalue expression, we could do only one of the copy assignment/constructor and move assignment/constructor. 3. , cv1 shall be const), or the reference shall be an rvalue reference. You switched accounts on another tab or window. A non-const reference may only be bound to an lvalue[/quote] 1 Reply Last reply Reply Quote 0. Visual C++ is non-compliant with the standard in allowing binding of temporaries to non-const lvalue references. I'll try paraphrasing it: In compiler version 2002, if the compiler had the choice if it would transform an object returned by a function to a non-const-reference or another type, it would have chosen the non-const-reference. If P is a forwarding reference and the argument is an lvalue, the type “lvalue reference to A ” is used in place of A for type deduction. rvalue Reference Cannot Bind to a Named lvalue. 4. Good article to understand both lvalue and rvalue references is C++ Rvalue References Explained. All rvalues are non-const. I understand this,. 1. A glvalue may be implicitly converted to a prvalue with lvalue-to-rvalue,. 3/5, [dcl. However, now you've got a temporary A, and that cannot bind to a, which is a non-const lvalue reference. This extends the lifetime of the temporary: base * const &rp = (base*)p; Or bind the reference to an lvalue: base * b = p; base * &rp = b; Share. If the initializer expression. Similar rationale is applied to the const qualifier. Allowing non-const references to bind to r-values leads to extremely confusing code. 5. First of all, I will post the warning I'm getting: xlist. 1/4 of N3337:. Actor actor = get_actor_ref_from_ped (PLAYER::PLAYER_PED_ID ()); Is going to make a copy of the value returned from the function as it calls the copy constructor. 5The Lvalue refers to a modifiable object in c++ that can be either left or right side of the assignment operator. However, I am. The reference in your example is bound to the constructor's argument n, and becomes invalid when the object n is bound to goes out of scope. I agree with the commenter 康桓瑋 that remove_rvalue_reference is a good name for this. For example, when passing things by value, or else with things like A a; B b = a;. Some older compilers couldn't support the latter in proper way. e. Non-compliant compilers might allow a non-const or volatile lvalue reference to be bound to an rvalue. C++. and if you pass it to a function that takes a reference to a non-const - it means that function can change the value. int & a=fun (); does not work because a is a non-const reference and fun () is an rvalue expression. an lvalue that refers to. From the C++20 draft. Ok, so, I already know that returning a local variable as reference will cause undefined behavior when we try to use it and that we can create a non-const reference to only form a lvalue variable. The const has nothing to do with the lifetime prolongation. However, when you use a const reference to a non-const object, you are asking the compiler to not let you modify the object through that particular. It's unclear what you mean by "has". Reference-compatibility allows extra cv-qualifications in the reference type. Actually the Standard say so: 8. e. , cv1 shall be const), or the reference shall be an rvalue reference. You are returning a reference to a local variable. This way, if the user passes in a U as an lvalue, it will be passed as U&, and if the user passes in a U as an rvalue, it will be passed as U&&. But result of such conversion is an rvalue, so your reference to non-const cannot be bound to it. A C++ reference is similar to a pointer, but acts more like an alias. 124 Non const lvalue references. But an rvalue reference can't bind to an lvalue because, as we've said, an rvalue reference refers to a value whose contents it's assumed we don't need to preserve (say, the parameter for a move constructor). However, lvalue references to const forbid any change to the object and thus you may bind them to an rvalue. Jan 8, 2015 at 8:51. a. Same thing can be done with lvalue references to const: const int& x = 10. Share. — Otherwise, the reference shall be an lvalue reference to a non-volatile const type (i. What getPtr () return: std::shared_ptr<int> getPtr (int val) { } is an rvalue reference. You are returning a copy of A from test so *c triggers the construction of a copy of c. , int and const int are similar, int* const ** volatile and volatile int** const * are similar, and crucially int* and. You can either modify the return type of the function from Value* to const Value& , or opt for return *cleverconfig[name]; . The problem is that a non-const lvalue reference cannot bind to a temporary, which is an rvalue. The temporary int's lifetime will be the same as the const reference. end()) is a temporary object and cannot be bound to lvalue reference. (コンパイラは VS2012) warning C4239: nonstandard extension used : 'initializing' : conversion from 'A' to 'A &' A non-const reference may only be bound to an lvalue. Return by value. e. There is a special rule in the language that allows binding a const lvalue reference to the rvalue (whether const or not) by extending the lifetime of the rvalue to match the lifetime of the. 3 of the C++11 standard: It doesn't allow expressions that bind a user-defined type temporary to a non-const lvalue reference. VS2008 is not too bad as at least it gives a compile warning: warning C4239: nonstandard extension used : 'initializing' : conversion from std::string to std::string & A non-const reference may only be bound to an lvalue A non-const reference may only be bound to an lvalue. obj & a1 = bar(); invalid initialization of non-const reference of type ‘obj&’ from an rvalue of type ‘obj’ using g++. However, an rvalue can be bound to a. The warning tells you your code now behaves differently than in earlier versions of Visual C++. e. qual] or even [conv. print(); This one matches the third constructor, and moves the value inside of the storage. Share. Rule: lvalue, rvalue, const or non-const objects can bind to const lvalue parameters. The call would bind to f(int&&). std::is_rvalue_reference<T&&>::valueA temporary can only bind to a reference to a prvalue. could be an AI. Thank you. Assume a variable name as a label attached to its location in memory. You can call a non-const member function on a temporary because this does not involve binding of a reference. This approach does not work for two reasons: First, because we modify the source object, we have to pass it as a non-const reference. Hot Network QuestionsNon-const references cannot bind to rvalues, it's as simple as that. If U is t’s underlying non-reference type (namely std::remove_reference_t<decltype(t)>), then T. C++ prohibits passing a temporary object as a non-const reference parameter. Because a reference to a non-const value can only bind to a modifiable lvalue (essentially a non. I get tired of writing a pair of iterators and make a View class. A non-const reference may only be bound to an lvalue[/quote] 1 Reply Last reply Reply Quote 0. It allows you to do something like swap(a, b), and it will actually swap the values of a and b, instead of having to do swap. – n. It can appear only on the right-hand side of the assignment operator. initial value of reference to non-const must be an lvalue. I have looked elsewhere on this site and read similar postings about this error: "initial value of reference to a non-const must be lvalue. 3 The initialization of non-const reference. Once it is bound, it's just a reference. (1) && attr  (optional) declarator. An rvalue may be used to initialize a const lvalue [ rvalue] reference, in which case the lifetime of the object identified by the rvalue is extended until the scope of the reference ends. The int* needs to be converted to void* firstly, which is a temporary object and could be bound to rvalue-reference. for example, to get a reference to the element. The non-const reference is converted into a const reference when the print function calls getConstReference. reference to type 'myclass' could not bind to an rvalue of type 'myclass *'. And this is precisely what the compiler is telling you:. So, in C++ (as in C) a = &b gets a pointer to b and stores this value in a, so if b is of type int, a needs to be of type int*. 80). only the first transfer succeeds. The second version is only allowed non- const rvalues because you can't implicitly strip const from the referencee and rvalue references don't allow lvalues to bind to them. is an xvalue, class prvalue, array prvalue or function lvalue and "cv1 T1" is reference-compatible with "cv2 T2", or. The forward should decay into an lvalue reference anyways, right? c++; perfect-forwarding; Share. The conformant behavior does not allow binding a non-const reference to an rvalue. A reference to the container element is obtained from the iterator with the indirection operator: *hand_it. We can't bind rvalue reference to an lvalue also. the expression c is an lvalue, even though the reference may have been bound to a temporary object at the time of calling. Not that std::forward has a return type that looks like T&&. If t returns a local variable, then you get a dangling reference, since that variable is gone after the call. You need to pass in an rvalue, and for that you need to use std::move: I can see why this is counter-intuitive!The site you got the code from is the explanation why this warning appears, it's the example code for reproducing it. Sounds like you actually want getPlayer to return a reference too and then to. Add a comment. Viewed 3k times. y()) < std::tie(b. So in your case, you need to rewrite your. The concepts of lvalue expressions and rvalue expressions are sometimes brain-twisting, but rvalue reference together with lvalue reference gives us more flexible options for programming. And the this pointer is a const pointer, so the instance cannot be changed. (Case 1 in the below program). 0 Invalid initialization of non-const reference from a. T and U) are never reference types. It's not against the rules in C++ to use a non-const reference but I think it lends to massive confusion and potential bugs. Now an lvalue reference is a reference that binds to an lvalue. Understand the design first before you implement. Universal reference is not an actual thing, it just means that we the parameter can have either an lvalue reference and rvalue reference type depending on template instantiation (which depends on the supplied argument at the call site). Only a named modifiable object. 3 -- Lvalue references ), we discussed how an lvalue reference can only bind to a modifiable lvalue. Share. Change the declaration of the function GetStart like: Point & GetStart(); Also at least the function GetEnd should be changed like: Point & GetEnd(); You could overload the functions for constant and non-constant objects: You may say, "ha, that's allowed because we want to provide the programmer with some flexibility to do "stupid" things that are in fact not that stupid", which is the reason I can hardly buy because if I buy this excuse, I think that "binding temporary to non-const lvalue reference" can be justified using the same reason. if binding temporary to local non-const lvalue reference is allowed, you may write the code like this :. Notably, types of expressions (i. However sometimes it is desired to ensure that you can only pass lvalues to a function (this is the case for std::ref for one). rvalues can be residing on read-only memory spaces where changing them might not be allowable and hence the compiler prohibits them. A non-const reference may only be bound to an lvalue[/quote] Reply Quote 0. C++ prohibits passing a temporary object as a non-const reference parameter. The relevant part of the standard is in [class. " followed by a specification of how the result of the conversion is determined. 2. Follow edited May 23, 2017 at 11:55. That is special syntax for a so-called forwarding reference. An expression that designates a bit-field (e. Lvalue reference to const. The literal 0 is still a poor choice for its default value, considering that 0 is an int, and your type is. For example, the argument might be a reference to a node of a linked list, and within the function you may want to traverse the list, so you will want to be doing node = * (node. You normally point to some spot in memory where you stored a value of interest. This allows you to explicitly move from an lvalue, using move. reference (such as the B& parameter in the B::B (B&) constructor) can only. a. You know, just like any other use of const. The parameter list for a move constructor, however, consists of an rvalue reference, like B&& x. */ } And called the function with: foo (createVector ()); It'd work fine. 4 Why Rvalue cannot bind Lvalue reference? 18 Invalid initialization of non-const reference of type. And const is a constraint imposed by the compiler to the variable that is declared as const. Notes: A non-const or volatile lvalue reference cannot be bound to anrvalue of a built-in type. Hence, B::B (A) will be selected, because there is a conversion from B to A. I am aware that a non-const reference can't bind to a temporary, but I really don't see why x2 can be considered as one and not x1. This seems to be well defined however (writing to a temporary value is just like writing to any value, the lifetime has no relevancy to the. C++/SDL "initial value of reference to a non-const must be an lvalue". thanks in advance, George. obj in f is an lvalue expression, and will therefore be treated as such. What you want is in 40two's answer, but make sure to forward the parameter t. A const lvalue reference can be initialized from a bit-field. It's not against the rules in C++ to use a non-const reference but I think it lends to massive confusion and potential bugs. { A res; res. Generally speaking, when a function takes a parameter by non-const. 5. A temporary or an rvalue cannot be changed with a reference to non-const. To reduce template instantiation overhead, I would recommend a more direct implementation:will result in output: Constructor called 42. int& func() { int x = 0; return x; } compiles, but it returns a reference to a stack variable that no longer exists. In the following post: Understanding lvalue/rvalue expression vs object type. Assume a variable name as a label attached to its location in memory. [3] Finally, this temporary variable is used as the value of the initializer. 1 Answer. 2005 and better will. rvalue reference versus non-const lvalue. Apr 14 at 22:55. R-value: r-value” refers to data value that is stored at some address in memory. Example 5 @relent95 Yes, whether the id-expression refers to a variable of reference or non-reference type doesn't matter because of what you quoted. Although the standard formulates it in other words (C++17 standard draft [dcl. g. –And I want to make sure template parameter F&& f only accept a non-const lvalue reference. m. The basic idea behind references is that lvalue references bind to lvalues, and rvalue references bind to rvalues; the reference thus bound henceforth refers to the value it was bound to. Unlike a reference to non-const (which can only bind to modifiable lvalues), a reference to const can bind to modifiable lvalues, non-modifiable lvalues, and rvalues. Second, our new version of the copy constructor will just as happily transplant the internals of lvalues: IntVector v1; IntVector v2 (v1); // v1 is no longer. If /Zc:referenceBinding is specified, the compiler follows section 8. Some similar case give me the reason: The C++ standard does not allow the binding of an anonymous temporary to a reference, although some compilers allow it as an extension. There are several (very constrained) circumstances in which the compiler, with language extensions enabled, will still allow a non-const lvalue reference to bind to an rvalue expression. 806 3 3 gold badges 12 12 silver badges 20 20 bronze badges. i. note: A non-const reference may only be bound to an lvalue. Undefined behavior can sometimes look like it's working. If t returns by lvalue reference, the code does not compile because a rvalue reference cannot bind to it. How to fix depends on what the return type of cleverConfig. Your conclusion happens to be correct, but it doesn't follow from your premise. On the contrary, rvalues can be bound to const lvalue references. This section presents an intentionally simplified definition of lvalues and rvalues. The option -qlanglvl=compatrvaluebinding instructs the compiler to allow a. However, int can be implicitly converted to double and this is happening. 1. Otherwise, if the reference is lvalue reference to a non-volatile const-qualified type or rvalue reference (since C++11): If target is a non-bit-field rvalue or a function lvalue, and its type is either T or derived from T , equally or less cv-qualified, then the reference is bound to the value of the initializer expression or to its base. Changing it to void display (const double& arg) works because everything works the same as explained above. int a = 7. Non-const reference may only be bound to an lvalue. If you want to capture the reference you need to declare a reference. Solution 3: When you call with , the address-of operator creates a temporary value , and you can't normally have references to temporary values because they are, well, temporary. You can normally hide the expression template type behind private members. This won't work. –Most of the time you don't want a non-const lvalue reference to refer to some temporary object. r can be bound to the conversion result of e or a base class of e if the following conditions are satisfied. only call const members of the object, you can not implicitly convert it to non-const, and you cannot perform non-const operations on its members. Assuming standard data sizes, you have a reference to 2 bytes of data that you're trying to pass into a function that takes a reference to only 1 byte. When you pass a pointer by a non- const reference, you are telling the compiler that you are going to modify that. Overload between rvalue reference and const lvalue reference in template. I can't understand why I have to specify the dynamic type to make it work. warning C4239: nonstandard extension used : 'initializing' : conversion from 'foo' to 'foo &' A non-const reference may only be bound to an lvalue (note that this remains illegal in C++11) Last edited on Dec 20, 2011 at 2:37am UTC Otherwise, if the reference is lvalue reference to a non-volatile const-qualified type or rvalue reference (since C++11): If target is a non-bit-field rvalue or a function lvalue, and its type is either T or derived from T , equally or less cv-qualified, then the reference is bound to the value of the initializer expression or to its base. )An variable name (which is normally an lvalue) can be moved in a return statement if it names an implicitly movable entity: An implicitly movable entity is a variable of automatic storage duration that is either a non-volatile object or an rvalue reference to a non-volatile object type. Non-explicit constructors have their uses. 1. int x; int&& r = x; but also. Every non-static data member of E must be a direct member of E or the same base class of E, and must be well-formed in the context of the structured binding when named as e. This function receives as a second parameter a const lvalue reference, this is an lvalue and then it calls to copy assignment. Note that for const auto& foo, const is qualified on the auto part, i. Declaring operator + to accept non-const references does not make. Then the type of foo would be Foo* const &, which is a reference to const (pointer to non-const Foo), but not const Foo* &, which is a reference to non-const (pointer to const Foo). If the initializer expression. //. GetCollider(). Lesley Lai has a blog post on this: “The implication. In the second case, fun() returns a non-const lvalue reference, which can bind to another non-const reference, of course. . 3 -- Lvalue references ), we discussed how an lvalue reference can only bind to a modifiable lvalue. unsigned int&). Lvalue references to const can be bound to. Properties -> C/C++ -> Language. The first variant returns a reference to the actual value associated with the key test, whereas the second one returns a reference to the map element, which is a pair<const key_type, mapped_type>, i. It got me quite curious. Sometimes even for the original developer, but definitely for future maintainers. Otherwise, the reference you get behaves more. 25th May 2022, 8:44 AM. void checkMe (shared_ptr<string>& param = shared_ptr<string> ()); This MSDN article says it is a /W4 warning. The only time that lifetime is extended is when a prvalue (or an xvalue referring to a member of a prvalue) is bound to a reference variable, and the lifetime of the prvalue is extended to that of the variable:. What is the reason behind disallowing binding an rvalue to an lvalue reference. 3. Of course the left value of an assignment has to be non-const. 3. at(0) = false; The reaons is that x. If t returns by rvalue reference, you obtain a reference to whatever was returned. The conversion produces an rvalue (i. I do not quite understand why there is a warning A non-const reference may only be bound to an lvalue and 'B::B (A)' called instead of 'B::B (B &)'? think. The problem is that auto and decltype side-step the whole public/private thing, allowing you to create types that you. e. int f( int ); int f( int && ); int f( int const & ); int q = f( 3 ); Removing f( int ) causes both Clang and GCC to prefer the rvalue reference over the lvalue reference. I do not quite understand why there is a warning A non-const reference may only be bound to an lvalue? A const reference can be bound to: R-value L-value A non-const reference can be bound to: L-value This means that you can do this: int const &x = 5; But you _can't_ do this: int &x = 5;, thus preventing you from trying to modify a. Note that the table indicates that an rvalue cannot bind to a non-const lvalue reference. Without the function, you are essentially writing: int x = 10; // x is an l-value int &get_x = x; // just a variable instead of a function get_x = 20; // assignment is ok By float&, he means he wants to take a reference to a float. But the principle is the same.