public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "hstong at ca dot ibm.com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-107962-4@http.gcc.gnu.org/bugzilla/> (raw) 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)
next reply other threads:[~2022-12-04 4:25 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-12-04 4:25 hstong at ca dot ibm.com [this message] 2022-12-04 4:38 ` [Bug c++/107962] " pinskia at gcc dot gnu.org 2023-08-06 23:23 ` hstong at ca dot ibm.com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107962-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).