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

David Blaikie dblaikie at gmail.com
Thu Nov 13 22:48:51 PST 2014


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)


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;
> }
> //}=======================================
> produces error:
> //{=======================================
>
> /home/evansl/dwnlds/llvm/3.5/binary/clang+llvm-3.5.0-x86_64-linux-gnu/bin/clang++
> -c -O0 -g -stdlib=libc++  -std=c++14 -ftemplate-backtrace-limit=0
> -I/home/evansl/prog_dev/clang/libcxx
> -I/home/evansl/prog_dev/boost/sandbox/rw/non_variadic_templates
> -I/home/evansl/prog_dev/boost/sandbox/rw/sandbox/lje
> -I/home/evansl/prog_dev/boost/boost-releases/ro/boost_1_56_0
> -DTYPE_AT_IMPL=0   -ftemplate-depth=324  variable_templates.cpp -MMD -o
> /tmp/build/clangxx3_5_bin/clang/libcxx/variable_templates.o
> variable_templates.cpp:23:39: error: non-static data member cannot be
> constexpr; did you intend to make it static?
>     std::integral_constant<int,Value> constexpr
>                                       ^
>                                       static
> 1 error generated.
> //}=======================================
> when compiled with the binary clang downloaded from:
>
>
>
> http://llvm.org/releases/3.5.0/clang+llvm-3.5.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz
>
> and used on system:
>
> Linux lje-OptiPlex-9020 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28
> 13:30:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
>
> The code is, AFAICT, essentially the same as the `struct
> matrix_measures' in section 3.2 of:
>
>   http://isocpp.org/files/papers/N3651.pdf
>
> Is this a clang bug or is the code somehow wrong?
>
> TIA.
>
> -regards,
> Larry
>
>
> _______________________________________________
> 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/20141113/22a7684d/attachment.html>


More information about the cfe-users mailing list