Is this an assignment to r-value?

F

Fedor Rodikov

After reading the [basic.lval] chapter in C++ standard I've written
the following simple test program to check my understanding:
int main()
{
int i;
(int(i)) = 0;
}

Here I try to assign a value to a temporary and this expression
compiles! But it shouldn't compile because we can't assign to r-value.

The C++standard in [basic.lval] says:
An expression which holds a temporary object resulting from a cast to
a nonreference is an rvalue (this includes the explicit creation of an
object using functional notation (5.2.3))

Where is inconsistency?

Thank you!
 
V

Victor Bazarov

After reading the [basic.lval] chapter in C++ standard I've written
the following simple test program to check my understanding:
int main()
{
int i;
(int(i)) = 0;
}

Here I try to assign a value to a temporary and this expression
compiles! But it shouldn't compile because we can't assign to r-value.

The C++standard in [basic.lval] says:
An expression which holds a temporary object resulting from a cast to
a nonreference is an rvalue (this includes the explicit creation of an
object using functional notation (5.2.3))

Where is inconsistency?

You should ask the compiler suppliers - it's apparently a buggy one.

V
 
J

Joshua Maurice

After reading the [basic.lval] chapter in C++ standard I've written
the following simple test program to check my understanding:
int main()
{
     int i;
     (int(i)) = 0;

}

Here I try to assign a value to a temporary and this expression
compiles! But it shouldn't compile because we can't assign to r-value.

The C++standard in [basic.lval] says:
An expression which holds a temporary object resulting from a cast to
a nonreference is an rvalue (this includes the explicit creation of an
object using functional notation (5.2.3))

Where is inconsistency?

Are you using microsoft visual studios? With its default compiler
options, it has several bugs, like this one. Try turning off compiler
extensions in the project settings. IIRC that should make it flag it
as an error.
 
F

Fedor Rodikov

After reading the [basic.lval] chapter in C++ standard I've written
the following simple test program to check my understanding:
int main()
{
     int i;
     (int(i)) = 0;

Here I try to assign a value to a temporary and this expression
compiles! But it shouldn't compile because we can't assign to r-value.
The C++standard in [basic.lval] says:
An expression which holds a temporary object resulting from a cast to
a nonreference is an rvalue (this includes the explicit creation of an
object using functional notation (5.2.3))
Where is inconsistency?

Are you using microsoft visual studios? With its default compiler
options, it has several bugs, like this one. Try turning off compiler
extensions in the project settings. IIRC that should make it flag it
as an error.

Yes! That is the VC++ extension. After applying \Za compiler option
the error appeared.

Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top