https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94511
Bug ID: 94511 Summary: User-defined type in non-type template parameter yields an incorrect value Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pacoarjonilla at yahoo dot es Target Milestone: --- g++ --std=c++2a code.cc && ./a.out The following snippet misbehaves with GCC9 and GCC10 master <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #include <cstddef> #include <iostream> 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 print(A a) { for (int i = 0; i < 6; i++) std::cout << (unsigned)a.data[i] << ' '; std::cout << std::endl; } using Bn = B<{'\n'}>; // XXX Replacing \n by any other character less than 48 corrects the issue XXX using Ba = B<{'.'}>; template <A T> void foo () { print(T); } int main() { foo<'*'>(); // XXX Replacing the * also corrects the issue XXX print(A{'*'}); } <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Expected output 0 0 0 0 0 4 0 0 0 0 0 4 Actual output 0 4 0 0 0 0 0 0 0 0 0 4