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

            Bug ID: 92099
           Summary: static_assert of struct template of false_type succeed
                    with GCC8 but not GCC9
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sunxuanmailbox at 163 dot com
  Target Milestone: ---

I'm using a type-dependent struct to enable static_assert inside contexpr if.
The following code compiles fine with GCC8/clang/msvc but fails with GCC9 at
static_assert

#include <iostream>
#include <type_traits>

using namespace std;

// this cause the problem
template <typename T>
struct DependentFalse : false_type
{
};

// this works fine
template <typename T>
constexpr false_type always_false{};

enum class E
{
    a,
    b,
    c
};

template <E id>
void f()
{
    if constexpr (id == E::a)
    {
        cout << "a" << endl;
    }
    else if constexpr (id == E::b)
    {
        cout << "b" << endl;
    }
    else
    {
        // compile error with gcc 9.2, ok with gcc 8.3/clang/msvc
        static_assert(DependentFalse<decltype(id)>::value, "Unknown id.");
        // ok with both
        static_assert(always_false<decltype(id)>.value, "Unknown id.");
    }
}

int main()
{
    f<E::a>();
}


The error message is:
main.cpp: In function ‘void f()’:
main.cpp:35:53: error: static assertion failed: Unknown id.
   35 |         static_assert(DependentFalse<decltype(id)>::value, "Unknown
id.");
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~

Reply via email to