[cfe-users] variable template within class produces non-static data member cannot be constexpr

Larry Evans cppljevans at suddenlink.net
Sat Nov 15 06:33:12 PST 2014



On 11/15/2014 06:59 AM, Gabriel Dos Reis wrote:
> On Fri, Nov 14, 2014 at 4:23 AM, Larry Evans <cppljevans at suddenlink.net>
> wrote:
> 
>> On 11/14/2014 12:48 AM, David Blaikie wrote:
>>> My guess is that the proposal was written assuming a certain
>> implementation
>>> of constexpr that never panned out.
>>>
>>> It looks like both GCC and Clang expect constexpr member variables to be
>>> explicitly marked static:
>>>
>>> const.cpp:5:19: error: non-static data member 'f' declared 'constexpr'
>>>    constexpr foo f{};
>>>                    ^
>>>
>>> (is GCC 4.9's diagnostic - for a simple non-template constexpr member
>> variable)
>>>
>> That's sad because, as n3651 says on pp. 2-3:
>>
>>   The main problems with “static data member” are:
>>
>>   • they require “duplicate” declarations: once inside the class
>>     template, once outside the class template to provide the “real”
>>     definition in case the constants is odr-used.
>>
> 
> then don't put it in a class.
> 

But then I don't understand why the problem was mentioned in n3651 on
pp. 2-3.  I thought one of the reasons for the proposal was to free
programmers from the need for "duplicate" declarations; however, the
solution:

  don't put it in a class

seems to indicate that the problem can be avoided simply by not
creating the problem.  IOW, the "duplicate" declaration in the
archetypical example on p. 2, the numeric_limits example, can be
avoided by not putting it in a template class (or struct in this
case).

In that case, I don't understand the rationale for proposal.

I must be missing something :(

-regards,
Larry

[snip]



More information about the cfe-users mailing list