This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/49311] Missing static const symbol with -O0


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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-06-08 08:02:19 UTC ---
(In reply to comment #4)
> (In reply to comment #3)
> > This is a dup of 
> 
> I think there are several hundred already. Not worth marking them as duplicate,
> it just further upsets people receiving notifications for a problem that has no
> solution.

Agreed, I provided them only for the reporter to get some additional background
to explain why this is definitely definitely not a bug.

(In reply to comment #5)
> > I think there are several hundred already.
> 
> Oh, this list was helpful, thanks!
> 
> > Not worth marking them as duplicate,
> > it just further upsets people receiving notifications for a problem that has no
> > solution.
> 
> Looking at http://www2.research.att.com/~bs/bs_faq2.html#in-class I found this
> 
>   "You can take the address of a static member if (and only if) it has an
> out-of-class definition"
> 
> Of course this is not a promise you don't need an out-of-class definition if
> you don't take the address. Gcc uses the assumption it can take the address in
> -O0 mode, but is this assumption justified? It's at least surprising.
> 
> class A
> {
> public:
>   static const unsigned first = 1;
>   enum { second = 2 };
> };
> 
> should behave similar in all cases address of first isn't taken.

But your code requires an lvalue because the result of the conditional operator
is an lvalue if both arguments are lvalues, so it must have an address.

That's why casting the operands or adding zero makes it link, because it makes
the operand an rvalue, so the address is not needed.

This is explained in the duplicate PRs I linked to, please read them, there's
nothing more to discuss IMHO.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]