public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/98424] New: The point of destroying temporary objects when initializing an array
@ 2020-12-23 3:01 xmh970252187 at gmail dot com
2021-09-19 6:51 ` [Bug c++/98424] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: xmh970252187 at gmail dot com @ 2020-12-23 3:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98424
Bug ID: 98424
Summary: The point of destroying temporary objects when
initializing an array
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: xmh970252187 at gmail dot com
Target Milestone: ---
#include <iostream>
struct A{
A(int id):id_(id){}
~A(){
std::cout<<"destroy A with id: "<<id_<<"\n";
}
int id_;
};
struct B{
B(A const&){
std::cout<<"construct from A\n";
}
};
int main(){
B arr[2] = {{0},{1}};
}
GCC destroy each temporary object that was bound to the parameter of `B(A
const&)` before initializing the next element.
The print is https://godbolt.org/z/j9MMqE:
````
construct from A
destroy A with id: 0
construct from A
destroy A with id: 1
````
According to
[class.temporary#6.1](https://timsong-cpp.github.io/cppwp/n4659/class.temporary#6.1).
>A temporary object bound to a reference parameter in a function call persists until the completion of the full-expression containing the call.
That means all temporary objects should be destroyed after the initialization
for `arr` has completed. Presumably, it is a bug of GCC that when to destroy
these temporary objects
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/98424] The point of destroying temporary objects when initializing an array 2020-12-23 3:01 [Bug c++/98424] New: The point of destroying temporary objects when initializing an array xmh970252187 at gmail dot com @ 2021-09-19 6:51 ` pinskia at gcc dot gnu.org 2021-09-23 9:56 ` xmh970252187 at gmail dot com 2023-05-08 12:57 ` ppalka at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-09-19 6:51 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98424 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Hmm, ICC and MSVC both have the same behavior as GCC. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/98424] The point of destroying temporary objects when initializing an array 2020-12-23 3:01 [Bug c++/98424] New: The point of destroying temporary objects when initializing an array xmh970252187 at gmail dot com 2021-09-19 6:51 ` [Bug c++/98424] " pinskia at gcc dot gnu.org @ 2021-09-23 9:56 ` xmh970252187 at gmail dot com 2023-05-08 12:57 ` ppalka at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: xmh970252187 at gmail dot com @ 2021-09-23 9:56 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98424 --- Comment #2 from jim x <xmh970252187 at gmail dot com> --- Clang destroys them at the end of the full-expression, see https://godbolt.org/z/3xhPjoh8c ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/98424] The point of destroying temporary objects when initializing an array 2020-12-23 3:01 [Bug c++/98424] New: The point of destroying temporary objects when initializing an array xmh970252187 at gmail dot com 2021-09-19 6:51 ` [Bug c++/98424] " pinskia at gcc dot gnu.org 2021-09-23 9:56 ` xmh970252187 at gmail dot com @ 2023-05-08 12:57 ` ppalka at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: ppalka at gcc dot gnu.org @ 2023-05-08 12:57 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98424 Patrick Palka <ppalka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=94041 CC| |ppalka at gcc dot gnu.org Target Milestone|--- |12.0 --- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> --- It seems this is fixed for GCC 12+ by r12-6328-gbeaee0a871b648. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-08 12:57 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-12-23 3:01 [Bug c++/98424] New: The point of destroying temporary objects when initializing an array xmh970252187 at gmail dot com 2021-09-19 6:51 ` [Bug c++/98424] " pinskia at gcc dot gnu.org 2021-09-23 9:56 ` xmh970252187 at gmail dot com 2023-05-08 12:57 ` ppalka at gcc dot gnu.org
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).