lvalue-to-rvalue

Does the standard mandate an lvalue-to-rvalue conversion of the pointer variable when applying indirection?

吃可爱长大的小学妹 提交于 2019-11-27 08:52:54
TL;DR Given the following code: int* ptr; *ptr = 0; does *ptr require an lvalue-to-rvalue conversion of ptr before applying indirection? The standard covers the topic of lvalue-to-rvalue in many places but does not seem to specify enough information to determine whether the * operator require such a conversion. Details The lvalue-to-rvalue conversion is covered in N3485 in section 4.1 Lvalue-to-rvalue conversion paragraph 1 and says ( emphasis mine going forward ): A glvalue (3.10) of a non-function, non-array type T can be converted to a prvalue.53 If T is an incomplete type, a program that

Array and Rvalue

陌路散爱 提交于 2019-11-27 07:41:21
问题 $4.2/1 - "An lvalue or rvalue of type “array ofN T” or “array of unknown bound of T” can be converted to an rvalue of type “pointer to T.” The result is a pointer to the first element of the array." I am not sure how do we get an rvalue of an array type other than during initialization/declaration? 回答1: I'm not sure what you refer to by "initialization/declaration" in this context. In the following, the array is a prvalue template<typename T> using alias = T; int main() { return alias<int[]>

lvalue to rvalue implicit conversion

风流意气都作罢 提交于 2019-11-27 03:20:59
I see the term "lvalue-to-rvalue conversion" used in many places throughout the C++ standard. This kind of conversion is often done implicitly, as far as I can tell. One unexpected (to me) feature of the phrasing from the standard is that they decide to treat lvalue-to-rvalue as a conversion. What if they had said that a glvalue is always acceptable instead of a prvalue. Would that phrase actually have a different meaning? For example, we read that lvalues and xvalues are examples of glvalues. We don't read that lvalues and xvalues are convertible to glvalues. Is there a difference in meaning?

Understanding the example on lvalue-to-rvalue conversion

吃可爱长大的小学妹 提交于 2019-11-26 23:17:22
I have a hard time understanding how this code (an example from the C++14 draft standard [conv.lval] ) invokes undefined behavior for g(false) . Why does constexpr make the program valid? Also, what does it mean by "does not access y.n "? In both calls to g() we are returning the n data member so why does the last line say it doesn't access it? struct S { int n; }; auto f() { S x { 1 }; constexpr S y { 2 }; return [&](bool b) { return (b ? y : x).n; }; } auto g = f(); int m = g(false); // undefined behavior due to access of x.n outside its // lifetime int n = g(true); // OK, does not access y

Why doesn't C++ move construct rvalue references by default? [duplicate]

徘徊边缘 提交于 2019-11-26 22:25:31
问题 This question already has an answer here: Rvalue Reference is Treated as an Lvalue? 4 answers Lvalue reference constructor is called instead of rvalue reference constructor 1 answer Say I have the following function void doWork(Widget && param) // param is an LVALUE of RRef type { Widget store = std::move(param); } Why do I need to cast param back to an rvalue with std::move() ? Shouldn't it be obvious that the type of param is rvalue since it was declared in the function signature as an

lvalue to rvalue implicit conversion

自古美人都是妖i 提交于 2019-11-26 10:27:04
问题 I see the term \"lvalue-to-rvalue conversion\" used in many places throughout the C++ standard. This kind of conversion is often done implicitly, as far as I can tell. One unexpected (to me) feature of the phrasing from the standard is that they decide to treat lvalue-to-rvalue as a conversion. What if they had said that a glvalue is always acceptable instead of a prvalue. Would that phrase actually have a different meaning? For example, we read that lvalues and xvalues are examples of

Understanding the example on lvalue-to-rvalue conversion

拜拜、爱过 提交于 2019-11-26 08:38:23
问题 I have a hard time understanding how this code (an example from the C++14 draft standard [conv.lval] ) invokes undefined behavior for g(false) . Why does constexpr make the program valid? Also, what does it mean by \"does not access y.n \"? In both calls to g() we are returning the n data member so why does the last line say it doesn\'t access it? struct S { int n; }; auto f() { S x { 1 }; constexpr S y { 2 }; return [&](bool b) { return (b ? y : x).n; }; } auto g = f(); int m = g(false); //