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

Larry Evans cppljevans at suddenlink.net
Thu Nov 13 20:38:40 PST 2014


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





More information about the cfe-users mailing list