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

            Bug ID: 66260
           Summary: [C++14] Failure to compile variable template with
                    recursively defined partial specialization
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Casey at Carter dot net
  Target Milestone: ---

Created attachment 35604
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35604&action=edit
testcase.cpp

Both GCC 5.1.0 and 6.0 fail to compile this program:

template <class>
constexpr bool foo = false;
template <>
constexpr bool foo<int> = true;
template <class T, int N>
constexpr bool foo<T[N]> = foo<T>;

static_assert(foo<int>, "");
static_assert(!foo<double>, "");
static_assert(foo<int[3]>, "");
static_assert(!foo<double[3]>, "");
static_assert(foo<int[2][5][3]>, "");
static_assert(!foo<double[2][5][3]>, "");

int main() {}

5.1.0 doesn't seem to recognize that foo is a template-name in the definition
of the foo<T[N]> partial specialization:

prog.cc:6:33: error: expected primary-expression before '>' token
 constexpr bool foo<T[N]> = foo<T>;
                                 ^
prog.cc:6:34: error: expected primary-expression before ';' token
 constexpr bool foo<T[N]> = foo<T>;
                                  ^
prog.cc:6: confused by earlier errors, bailing out

6.0 20150522 at least tries to compile the recursion, but fails nonetheless:

prog.cc: In instantiation of 'constexpr const bool foo':
prog.cc:6:16:   recursively required from 'constexpr const bool foo'
prog.cc:6:16:   required from 'constexpr const bool foo'
prog.cc:10:15:   required from here
prog.cc:6:16: fatal error: template instantiation depth exceeds maximum of 900
(use -ftemplate-depth= to increase the maximum)
 constexpr bool foo<T[N]> = foo<T>;
                ^
compilation terminated.

Reply via email to