public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization
@ 2022-01-29 13:10 fchelnokov at gmail dot com
2022-01-29 17:11 ` [Bug c++/104282] " pinskia at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-29 13:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282
Bug ID: 104282
Summary: Copy elision when initializing a base-class subobject
with aggregate initialization
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fchelnokov at gmail dot com
Target Milestone: ---
The program
```
#include <iostream>
struct A {
A() { std::cout << "A "; }
A(const A&) { std::cout << "Acopy "; }
A(A&&) { std::cout << "Amove "; }
~A() { std::cout << "~A "; }
};
struct B : A { };
int main() {
B b{ A{} };
}
```
if compiled by GCC, prints `A ~A `, showing that there is no copy/move of the
temporary `A{}`.
Clang prints on the other hand `A Amove ~A ~A `, which looks correct, because
of "no elision when initializing a base-class subobject", see
https://en.cppreference.com/w/cpp/language/copy_elision
Demo: https://gcc.godbolt.org/z/rafEsTdd9
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
@ 2022-01-29 17:11 ` pinskia at gcc dot gnu.org
2022-01-29 17:12 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-29 17:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Gcc 12 defaults to c++17. I have not looked but I suspect that is the
difference.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
2022-01-29 17:11 ` [Bug c++/104282] " pinskia at gcc dot gnu.org
@ 2022-01-29 17:12 ` pinskia at gcc dot gnu.org
2022-01-29 17:15 ` fchelnokov at gmail dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-29 17:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
That is c++17 requires Copy elision here while c++14 does not.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
2022-01-29 17:11 ` [Bug c++/104282] " pinskia at gcc dot gnu.org
2022-01-29 17:12 ` pinskia at gcc dot gnu.org
@ 2022-01-29 17:15 ` fchelnokov at gmail dot com
2022-01-29 19:26 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-29 17:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282
--- Comment #3 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
Both Clang and GCC do not change their output either with `-std=c++20` or with
`-std=c++17` options. And both reject the program with -std=c++14`.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
` (2 preceding siblings ...)
2022-01-29 17:15 ` fchelnokov at gmail dot com
@ 2022-01-29 19:26 ` redi at gcc dot gnu.org
2022-01-29 19:29 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-29 19:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think there's any existing bug about this, and it's an open issue in the ABI
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
` (3 preceding siblings ...)
2022-01-29 19:26 ` redi at gcc dot gnu.org
@ 2022-01-29 19:29 ` redi at gcc dot gnu.org
2022-01-29 23:34 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-29 19:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Related to https://github.com/itanium-cxx-abi/cxx-abi/issues/107
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
` (4 preceding siblings ...)
2022-01-29 19:29 ` redi at gcc dot gnu.org
@ 2022-01-29 23:34 ` pinskia at gcc dot gnu.org
2023-01-16 4:23 ` pinskia at gcc dot gnu.org
2024-03-22 7:52 ` fchelnokov at gmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-29 23:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2403
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
` (5 preceding siblings ...)
2022-01-29 23:34 ` pinskia at gcc dot gnu.org
@ 2023-01-16 4:23 ` pinskia at gcc dot gnu.org
2024-03-22 7:52 ` fchelnokov at gmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-16 4:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #4)
> I think there's any existing bug about this, and it's an open issue in the
> ABI
PR 98995 .
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
` (6 preceding siblings ...)
2023-01-16 4:23 ` pinskia at gcc dot gnu.org
@ 2024-03-22 7:52 ` fchelnokov at gmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: fchelnokov at gmail dot com @ 2024-03-22 7:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282
--- Comment #8 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
One more inconsistency here:
struct A {
A() {}
A(A&&) = delete;
};
struct B : A { };
int main() {
// ok in GCC
B{ A{} };
// error in GCC
B b{ A{} };
}
GCC allows temporary creation B{ A{} }, but prohibits variable creation B b{
A{} }. Online demo: https://gcc.godbolt.org/z/YGjYYqo6M
It looks like both must be prohibited as in Clang (or both allowed as in MSVC).
Related discussion: https://stackoverflow.com/q/70898525/7325599
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-03-22 7:52 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-29 13:10 [Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization fchelnokov at gmail dot com
2022-01-29 17:11 ` [Bug c++/104282] " pinskia at gcc dot gnu.org
2022-01-29 17:12 ` pinskia at gcc dot gnu.org
2022-01-29 17:15 ` fchelnokov at gmail dot com
2022-01-29 19:26 ` redi at gcc dot gnu.org
2022-01-29 19:29 ` redi at gcc dot gnu.org
2022-01-29 23:34 ` pinskia at gcc dot gnu.org
2023-01-16 4:23 ` pinskia at gcc dot gnu.org
2024-03-22 7:52 ` fchelnokov at gmail dot 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).