From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ECFE73855167; Sun, 4 Dec 2022 04:25:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ECFE73855167 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670127917; bh=x6yZRE9OGE143sH52fBJ7qpRjVvCfRpAB1BzAI14DBU=; h=From:To:Subject:Date:From; b=Pox99xIF9fy62rgo+Z5oK8ngMjlMZjuwFpo9oHznL9GzoSngAyMYZFoQcaKczfe9B QRZBSmBAsX3xG7pMLLr0DAhXEPe1QiCvT6IQKiU8RQfsMVGpvccVRNISukEVN9HsGi Qr5IXiz+CNvX7FKt/Xoxyh6776TjOWCCfLgQ6oao= From: "hstong at ca dot ibm.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107962] New: GCC allows constexpr copy construction despite uninitialized member Date: Sun, 04 Dec 2022 04:25:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: accepts-invalid X-Bugzilla-Severity: normal X-Bugzilla-Who: hstong at ca dot ibm.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107962 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 is= sue. Compiler Explorer link: https://godbolt.org/z/afq1h895a ### SOURCE (): struct A { int x, y; constexpr A() {} }; constexpr int f() { A a; a.x =3D 42; A b =3D a; return b.x; } extern constexpr int x =3D f(); ### COMPILER INVOCATION: g++ -xc++ -fsyntax-only -std=3Dc++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=3D/opt/wandbox/gcc-head/bin/g++ COLLECT_LTO_WRAPPER=3D/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=3D/opt/wandbox/gcc-head --enable-languages=3Dc,c++ --disable-multilib --without-ppl --without-cloog= -ppl --enable-checking=3Drelease --disable-nls --enable-lto LDFLAGS=3D-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)=