Questions tagged [prvalue]
30 questions
77
votes
2 answers
Cv-qualifications of prvalues (revisited)
This is a followup to my previous question, where the apparent consensus was that the change in treatment of cv-qualifications of prvalues was just a fairly minor and inconsequential change intended to solve some inconsistencies (e.g. functions…

AnT stands with Russia
- 312,472
- 42
- 525
- 765
15
votes
2 answers
How do we test if an expression of a certain type can be invoked with a prvalue?
With c++17 we have fancy new is_invocable and fancy new prvalues that aren't really values.
This permits you to create an object without having to first logically construct it, then elide the construction.
I have run into a problem where using…

Yakk - Adam Nevraumont
- 262,606
- 27
- 330
- 524
13
votes
3 answers
"expression must be an l-value or function designator" error when taking the address of this
I'm trying to do this in C++:
class Abc
{
int callFunction1()
};
void function1(Abc** c1) {//do something}
int Abc::callFunction1()
{
function1(&this);
return 0;
}
And I get "expression must be an l-value or function designator" error in…

disccip
- 573
- 3
- 5
- 15
7
votes
1 answer
Why is return throw std::exception() accepted in a void function?
I mistakenly pasted a throw statement after a return with the following final result:
void DXManager::initialize(const std::shared_ptr& ctx_ptr)
{
// ...
if (FAILED(result))
{
return throw std::exception("Failed to…

payloc91
- 3,724
- 1
- 17
- 45
7
votes
2 answers
Lifetime extension, prvalues and xvalues
Following the well accepted answer to this question Do rvalue references allow dangling references? It would seem that xvalues do not have their lifetime extended when assigned to a rvalue reference lvalue like in the question. However when I do…

Curious
- 20,870
- 8
- 61
- 146
6
votes
1 answer
Is prvalue elision allowed in throw expressions
In §[except.throw], the standard says that throwing an exception copy-initializes the exception object from the throw expression
Throwing an exception copy-initializes (11.6, 15.8) a temporary object, called the exception object
Why then does the…

Curious
- 20,870
- 8
- 61
- 146
6
votes
2 answers
xvalues vs prvalues: what does identity property add
I'm sorry for the broadness of the question, it's just that all these details are tightly interconnected..
I've been trying to understand the difference between specifically two value categories - xvalues and prvalues, but still I'm…

ledonter
- 1,269
- 9
- 27
5
votes
2 answers
Direct initialization with prvalue: Bug in MSVC?
Consider the following code:
struct S
{
S(int, double) {}
explicit S(const S&) {}
explicit S(S&&) {}
};
void i_take_an_S(S s) {}
S i_return_an_S() { return S{ 4, 2.0 }; }
int main()
{
i_take_an_S(i_return_an_S());
}
With the…

Ruperrrt
- 489
- 2
- 13
4
votes
0 answers
What is the difference between initializing an object and computing a value?
From the Working Draft, Standard for Programming Language C++, [basic.lval/5]:
The result of a glvalue is the entity denoted by the expression. The result of a prvalue is the value that the expression stores into its context; a prvalue that has…

Géry Ogam
- 6,336
- 4
- 38
- 67
3
votes
1 answer
Why doesn't "Guaranteed Copy Elision" mean that push_back({arg1, arg2}) is the same as emplace_back(arg1, arg2)?
Firstly, I've heard that Guaranteed Copy Elision is a misnomer (as, I currently understand, it's more about fundamentally redefining the fundamental value categories, r/l-values to l/x/pr-values, which fundamentally changes the meaning and…

Elliott
- 2,603
- 2
- 18
- 35
3
votes
1 answer
How references can bind to prvalues?
cppreference says that: a temporary object is created when a reference is bound to prvalue. Do they mean const lvalue references and rvalue references?:
Temporary objects are created when a prvalue is materialized so that it can be used as a…
user15676138
3
votes
2 answers
Make ++o++ complain for types with user defined pre- and postfix increment operators
I'm looking for a way to prevent ++x++ from working for types with user defined prefix and postfix increment operators.
For builtin types the result type of the postfix operator is not an lvalue but a prvalue expression and the compilers complain…

jesses
- 559
- 3
- 15
2
votes
1 answer
How to distinguish between pr-values and x-values
In the following code,
#include
struct literal_type
{
// ...
};
class my_type
{
public:
my_type(literal_type const& literal); // (1)
my_type(literal_type && literal); // (2)
// ...
};
void foo()
{
…

Arjonais
- 563
- 2
- 17
2
votes
1 answer
How expressions designating temporary objects are xvalue expression?
From cppreference, I am trying to understand expressions that yield xvalues, and I ended up with this summary:
The following expressions are xvalue expressions:
...
any expression that designates a temporary object, after…

mada
- 1,646
- 1
- 15
2
votes
2 answers
What does this mean "prvalue of type“ in C++ standard N3337 5.2.10 clause 7?
In C++ draft standard N3337 section 5.2.10 Reinterpret cast clause 7 (emphasis mine):
An object pointer can be explicitly converted to an object pointer to a different type. When a prvalue v of type “pointer to T1” is converted to the type “pointer…

dcthxd
- 41
- 4