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

            Bug ID: 87389
           Summary: if constexpr not working properly with static_assert
           Product: gcc
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tobias.bruell at gmail dot com
  Target Milestone: ---

Shouldn't the following compile? Also, if one replaces the hash_value_t by the
32-bit variant?

This is also rejected by Clang.

----------------------------------

#include <iostream>

//using hash_value_t = uint32_t;
using hash_value_t = uint64_t;

template<typename T, T v>
struct integer_ct {};

template<typename T, T v1, T v2>
constexpr bool operator == (integer_ct<T, v1>, integer_ct<T, v2>)
{
  return (v1 == v2);
};

template<typename T, T v>
constexpr auto hash (integer_ct<T, v>)
{
  return integer_ct<T, 2 * v> {};
}

int main ()
{
  if constexpr (sizeof (hash_value_t) == 4)
  {
    static_assert (hash (integer_ct<hash_value_t, 0x80000001> {}) ==
                         integer_ct<hash_value_t, 0x00000002> {});
  }
  else if constexpr (sizeof (hash_value_t) == 8)
  {
    static_assert (hash (integer_ct<hash_value_t, 0x8000000000000001> {}) ==
                         integer_ct<hash_value_t, 0x0000000000000002> {});
  }
}

Reply via email to