public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96223] New: DR 1787 and indeterminate values in constexpr context
@ 2020-07-16 19:30 mpolacek at gcc dot gnu.org
  2020-07-16 19:32 ` [Bug c++/96223] " mpolacek at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-07-16 19:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96223
           Summary: DR 1787 and indeterminate values in constexpr context
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-17 20:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 19:30 [Bug c++/96223] New: DR 1787 and indeterminate values in constexpr context mpolacek at gcc dot gnu.org
2020-07-16 19:32 ` [Bug c++/96223] " mpolacek at gcc dot gnu.org
2020-08-06 17:54 ` richard-gccbugzilla at metafoo dot co.uk
2020-08-06 18:00 ` mpolacek at gcc dot gnu.org
2020-09-17 20:15 ` cvs-commit at gcc dot gnu.org
2020-09-17 20:19 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).