[cfe-users] variable template within class produces non-static data member cannot be constexpr
Gabriel Dos Reis
gdr at integrable-solutions.net
Sat Nov 15 04:59:53 PST 2014
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.
>
> • programmers are both miffed and confused by the necessity of
> providing twice the same declaration. By contrast, “ordinary”
> constant declarations do not need duplicate declarations.
>
> Also, the clang status page:
>
> http://clang.llvm.org/cxx_status.html
>
> reference n3651 below the section title:
>
> C++14 implementation status
>
> Hence, I thought that's what clang implemented.
>
> In addition, the latest standard *draft*:
>
> https://isocpp.org/files/papers/N3797.pdf
>
> contains the n3651 matrix_constants example on p. 313.
>
> Is there some more current standards document which requires the
> static qualifier on variable templates within a class?
>
> TIA.
>
> -regards,
> Larry
>
> > On Thu, Nov 13, 2014 at 8:38 PM, Larry Evans <cppljevans at suddenlink.net>
> > wrote:
> >
> >> The following code:
> >>
> >> //{=======================================
> >> #include <type_traits>
> >> struct variable_template
> >> {
> >> template <int Value>
> >> std::integral_constant<int,Value> constexpr
> >> value{}
> >> ;
> >> };
> >> #include <iostream>
> >> #include <iomanip>
> >> int main()
> >> {
> >> std::cout<<
> >> variable_template::
> >> value<1>()<<std::endl;
> >> return 0;
> >> }
> >> //}=======================================
> [snip]
>
>
> _______________________________________________
> cfe-users mailing list
> cfe-users at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20141115/f6a97d8a/attachment.html>
More information about the cfe-users
mailing list