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

            Bug ID: 107962
           Summary: GCC allows constexpr copy construction despite
                    uninitialized member
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hstong at ca dot ibm.com
  Target Milestone: ---

Lvalue-to-rvalue conversion of objects having indeterminate value is not
allowed during evaluation of a core constant expression (see N4919 subclause
7.7 [expr.const] bullet 5.11). GCC allows such lvalue-to-rvalue conversion
during the constant evaluation of trivial copy constructors.

In the case below, the `y` member of `a` has indeterminate value when the
initialization of `b` is performed. Clang and ICC correctly diagnose the issue.

Compiler Explorer link: https://godbolt.org/z/afq1h895a

### SOURCE (<stdin>):
struct A {
  int x, y;
  constexpr A() {}
};

constexpr int f() {
  A a;
  a.x = 42;
  A b = a;
  return b.x;
}

extern constexpr int x = f();


### COMPILER INVOCATION:
g++ -xc++ -fsyntax-only -std=c++2a -


### ACTUAL OUTPUT:
(Clean compile)


### EXPECTED OUTPUT:
(Error that `x` is not initialized by a constant expression)


### COMPILER VERSION INFO (g++ -v):
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head
--enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl
--enable-checking=release --disable-nls --enable-lto
LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20221202 (experimental) (GCC)

Reply via email to