[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: static const int optimization fails in conditional expressions



> Compilers are allowed to optimize static const integral members, in the
> sense that their values may be used directly.

Right.  I'm reporting that

1) gcc's behavior changed in this regard in 2.96 and 3.00 from 2.95 and
   previous, and 
2) gcc sometimes uses these values directly without defining the variables,
   while other times gcc chooses not to use these values directly.

As I understand, gcc used these values directly with the described
conditional expression in 2.95, so that there was never a need to define
these variables.

> That has nothing to do with the requirement that static members must
> still be defined.

On this requirement, gcc is not consistent:  sometimes it uses the values
directly, while other times, it requires you define the variables.  It
should not special case :? to fail.

There are two ways gcc can be made consistent:  
1) disable the use of these values directly in all cases, or 
2) re-enable the use of these values in the ?: conditional expressions.

(I'm in favor of #2, but would favor consistency above all else.)

> > The following code compiles cleanly:
> 
> But you haven't tried to link it yet, have you? The program isn't done
> until the linker's finished. :-)

My bad.  I should have said "The following code compiles and links
cleanly."

james



Reply to: