http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49311

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-06-08 
10:27:28 UTC ---
(In reply to comment #7)
> 
> Does the way I use an rvalue change it's definition?

I don't understand the question, I don't know what you mean by the definition
of an rvalue.

> So if A and B are rvalue's does
>   c = x ? A : B
> to mutate to lvalues?

No of course not.

If A and B are both lvalues of the same type then (x ? A : B) is an lvalue. 
Otherwise (x ? A : B) is an rvalue.

This is a simplification, check the rules for yourself in the C++ standard if
you want the gory details.

> Looking at http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#454
> the compiler should handle static const data members like rvalues wherever
> possible. Currently gcc does so nearly all the time, the few exceptions cause
> really unexpected troubles

The proposed resolution shown in DR 454 was not applied to the draft, it was
resolved differently.

G++ handles your code correctly, it is invalid C++. Consider if foo is
rewritten as:

unsigned foo(int direction)
{
   const unsigned char& result = direction==0 ? A::PEN : A::NEN;
   return result;
}

This takes a reference to an lvalue, which requires it to have an address.

The solution is simple, just fix your code.

This is not a bug.

Reply via email to