public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107962] New: GCC allows constexpr copy construction despite uninitialized member
@ 2022-12-04 4:25 hstong at ca dot ibm.com
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
0 siblings, 2 replies; 3+ messages in thread
From: hstong at ca dot ibm.com @ 2022-12-04 4:25 UTC (permalink / raw)
To: gcc-bugs
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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/107962] GCC allows constexpr copy construction despite uninitialized member
2022-12-04 4:25 [Bug c++/107962] New: GCC allows constexpr copy construction despite uninitialized member hstong at ca dot ibm.com
@ 2022-12-04 4:38 ` pinskia at gcc dot gnu.org
2023-08-06 23:23 ` hstong at ca dot ibm.com
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-04 4:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107962
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-12-04
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/107962] GCC allows constexpr copy construction despite uninitialized member
2022-12-04 4:25 [Bug c++/107962] New: GCC allows constexpr copy construction despite uninitialized member hstong at ca dot ibm.com
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
1 sibling, 0 replies; 3+ messages in thread
From: hstong at ca dot ibm.com @ 2023-08-06 23:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107962
--- Comment #2 from Hubert Tong <hstong at ca dot ibm.com> ---
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2264 suggests that
the GCC behaviour may be the desired one because copies of
partially-initialized structures are allowed in C but cause undefined behaviour
in C++.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-06 23:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-04 4:25 [Bug c++/107962] New: GCC allows constexpr copy construction despite uninitialized member hstong at ca dot ibm.com
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
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).