new requirement of "constexpr" for static const float data members is too restrictive

Marc Glisse marc.glisse@inria.fr
Tue Nov 30 14:07:00 GMT 2010


On Tue, 30 Nov 2010, Richard Guenther wrote:

> On Tue, Nov 30, 2010 at 9:17 AM, Miles Bader <miles@gnu.org> wrote:
>> On Tue, Nov 30, 2010 at 5:13 PM, Gabriel Dos Reis
>> <gdr@integrable-solutions.net> wrote:
>>> If you are doing that, why don't you write a simpler code by
>>> just defining (e.g. initializing) the data member outside the class?
>>
>> 'cause I want the compiler to be able to use (inline) the underlying values.
>
> I think it'll do that with initializing the member outside of the class as well.
>
> struct X { static float const v; };
> const float X::v = 1;
> int main()
> {
>  return (int)X::v;
> }
>
> at least works for me (even when not optimizing - huh).

I don't know the OP's code, but X would typically be in a header file, 
included in several translation units. And there is no static or inline 
you can write in front of "const float X::v = 1;" to help with that.

(with LTO the optimizations might still happen with X::v defined 
separately)

-- 
Marc Glisse



More information about the Gcc mailing list