https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66921

            Bug ID: 66921
           Summary: failure to determine size of static constexpr array
                    that is nested within a templated class
           Product: gcc
           Version: 4.9.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vlad at petric dot cc
  Target Milestone: ---

Created attachment 36010
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36010&action=edit
straightforward file (include-less) that fails to compile

template<typename T>
struct Holder {
  constexpr static const int array[] = { 1, 2, 3 };
  enum {F = array[0]};
};

class HI: public Holder<int> {};

gcc 4.9.3/Centos linux.

$ g++ -std=c++11 ./x.cc -o x.o -c
./x.cc: In instantiation of ‘constexpr const int Holder<int>::array []’:
./x.cc:4:18:   required from ‘struct Holder<int>’
./x.cc:7:18:   required from here
./x.cc:3:30: error: initializer fails to determine size of ‘Holder<int>::array’
   constexpr static const int array[] = { 1, 2, 3 };
                              ^
./x.cc:3:30: error: array must be initialized with a brace-enclosed initializer
./x.cc: In instantiation of ‘struct Holder<int>’:
./x.cc:7:18:   required from here
./x.cc:4:8: error: enumerator value for ‘F’ is not an integer constant
   enum {F = array[0]};



* with gcc 4.8.3, it compiles just fine.

* if I remove the template, it also compiles just fine:

struct Holder {
  constexpr static const int array[] = { 1, 2, 3 };
  enum {F = array[0]};
};

class HI: public Holder {};

Reply via email to