Is this an assignment to r-value?

Discussion in 'C++' started by Fedor Rodikov, Nov 14, 2011.

  1. 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!
     
    Fedor Rodikov, Nov 14, 2011
    #1
    1. Advertising

  2. On 11/14/2011 9:47 AM, Fedor Rodikov wrote:
    > 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
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Nov 14, 2011
    #2
    1. Advertising

  3. On Nov 14, 6:47 am, Fedor Rodikov <> wrote:
    > 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.
     
    Joshua Maurice, Nov 14, 2011
    #3
  4. On Nov 15, 1:36 am, Joshua Maurice <> wrote:
    > On Nov 14, 6:47 am, Fedor Rodikov <> wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > 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!
     
    Fedor Rodikov, Nov 15, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christopher
    Replies:
    1
    Views:
    342
    Victor Bazarov
    Sep 12, 2003
  2. nagy
    Replies:
    36
    Views:
    1,011
    Terry Reedy
    Jul 20, 2006
  3. John Goche

    assignment of integer to enumerated value

    John Goche, Nov 24, 2006, in forum: C Programming
    Replies:
    7
    Views:
    348
    Ian Collins
    Nov 24, 2006
  4. gsyoon
    Replies:
    4
    Views:
    392
    gsyoon
    Aug 11, 2005
  5. Chris
    Replies:
    34
    Views:
    1,525
Loading...

Share This Page