Use -std=c++20: // DR 1787 #include <cstddef> constexpr int fn1 () { unsigned char foo; unsigned char u = foo; // OK: u has an indeterminate value return u; // UB: copy-init -> standard conversion to int } constexpr int fn2 () { unsigned char foo; int i = foo; // UB return 0; } constexpr int fn3 () { unsigned char foo; char8_t u = foo; // UB: char8_t not an unsigned ordinary character type return 0; } constexpr int fn4 () { std::byte foo; std::byte b = foo; // OK return 0; } constexpr int w1 = fn1 (); constexpr int w2 = fn2 (); constexpr int w3 = fn3 (); constexpr int w4 = fn4 (); DR 1787 says that if an indeterminate value is produced by an evaluation, the behavior is undefined except in certain cases. In fn1 and fn4 we issue errors even for some of the "certain cases" (the lines marked with OK) and I think it's a bug. Uninitialized variables in a constexpr context are OK since C++20 P1331R2.
Note that is_byte_access_type won't do, because it includes char8_t too.
P1331R2 explicitly disallows in a constant evaluation: "- an lvalue-to-rvalue conversion that is applied to an object with indeterminate value ([basic.indet]);" so GCC is correct to reject such cases.
Aaah, I see. Thanks a lot! I'll add the test at least.
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:4f0aa5b051c0d3e81478bcb495e4e072b2d9827d commit r11-3268-g4f0aa5b051c0d3e81478bcb495e4e072b2d9827d Author: Marek Polacek <polacek@redhat.com> Date: Thu Sep 17 15:31:50 2020 -0400 c++: Add tests for fixed PRs. Bugzilla inspection turned up a bunch of old(er) PRs that have been fixed. Let's include them not to regress in the future. gcc/testsuite/ChangeLog: PR c++/87530 PR c++/58156 PR c++/68828 PR c++/86002 PR c++/91525 PR c++/96223 PR c++/87032 PR c++/35098 * g++.dg/cpp0x/move-return4.C: New test. * g++.dg/cpp0x/vt-58156.C: New test. * g++.dg/cpp2a/concepts-pr68828.C: New test. * g++.dg/cpp2a/concepts-pr86002.C: New test. * g++.dg/cpp2a/concepts-pr91525.C: New test. * g++.dg/cpp2a/constexpr-indeterminate1.C: New test. * g++.dg/cpp2a/desig17.C: New test. * g++.dg/ext/attrib62.C: New test.
Test added.