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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Note, the testcase isn't portable, so either would need to be restricted for
ascii compatible execution charsets only, or the check would need to be
replaced with i == ('*' / 8) ? 1U << ('*' % 8) : 0
(and deal with '*' >= 64 where it would be a compile time error).
Or use '\x0a' and '\x2a' instead of '\n' and '*'.

namespace std {
  enum class byte : unsigned char {};
  constexpr byte
  operator| (byte __l, byte __r) noexcept
  { return (byte)(unsigned char)((unsigned)__l | (unsigned)__r); }
  constexpr byte&
  operator|= (byte& __l, byte __r) noexcept
  { return __l = __l | __r; }
}

struct A {
  std::byte data [6] {static_cast<std::byte> (0x00)};
  constexpr A (char ch) { data[ch/8] |= static_cast<std::byte>(0x01 << (ch %
8)); }
};

template <A chars> struct B { char ch; };

void
check (A a)
{
  for (int i = 0; i < 6; i++)
    if ((unsigned) a.data[i] != (i == 5 ? 4 : 0))
      __builtin_abort ();
}

using Bn = B<{'\x0a'}>;

template <A T>
void
foo ()
{
  check (T);
}

int
main ()
{
  foo<'\x2a'> ();
  check (A{'\x2a'});
}

Reply via email to