[Bug c++/96124] New: Template specialization auto

amal029 at outlook dot com gcc-bugzilla@gcc.gnu.org
Wed Jul 8 19:57:39 GMT 2020


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

            Bug ID: 96124
           Summary: Template specialization auto
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amal029 at outlook dot com
  Target Milestone: ---

#include <iostream>

template <auto N, auto M> 
struct Add {
  const static auto res = Add<N + 1, M - 1>::res;
};

template <auto N> 
struct Add<N, 0> { const static auto res = N; };

/* This does not work, the second template argument overflows in Add struct */
/* Clang handles both cases correctly. */
template <std::size_t N>

//template <auto N> /* This works uncomment this line and comment the above
line to make it work */
auto Forall() { return Forall<N - 1>() + Add<N, N - 1>::res; }

template <> 
auto Forall<0>() { return 0; }

int main(void) {
  std::cout << Forall<3>() << "\n";
  return 0;
}

See the comments in the code. I ran it on compiler explorer with both g++ 10.1
and gcc-trunk (x86-64); both fail. I should be able to narrow types myself.

Options when compiling -std=c++2a


More information about the Gcc-bugs mailing list