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

            Bug ID: 88242
           Summary: static_assertion only fires when class is templated
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fiesh at zefix dot tv
  Target Milestone: ---

The following code compiles iff -DFIX is supplied.  Clang compiles it both with
and without -DFIX.  Please let me know what else I can do to help debug this
problem, I'm not certain what would be helpful.

#include <array>
#include <tuple>

template <int N>
struct Number : public Number<N - 1>
{
        static constexpr int value = N;
};

template <>
struct Number<0>
{
        static constexpr int value = 0;
};

using Max = Number<16>;

#ifndef FIX
template <typename = void>
#endif
struct C
{
        static constexpr std::array<int, 0> f(Number<0>) { return
std::array<int, 0>{}; }

        static constexpr auto f(Number<std::tuple_size_v<decltype(f(Max{}))> +
1> n) -> std::array<int, decltype(n)::value>
        {
                static_assert(n.value == 1);
                return std::array<int, decltype(n)::value>{};
        }

        static constexpr auto f(Number<std::tuple_size_v<decltype(f(Max{}))> +
1> n) -> std::array<int, decltype(n)::value>
        {
                static_assert(n.value == 2);
                return std::array<int, decltype(n)::value>{};
        }

        static constexpr auto x() { return f(Max{}); }
};

#ifdef FIX
using D = C;
#else
using D = C<>;
#endif

static_assert(D::x().size() == 2);

Reply via email to