public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "xmh970252187 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/98424] New: The point of destroying temporary objects when initializing an array
Date: Wed, 23 Dec 2020 03:01:13 +0000 [thread overview]
Message-ID: <bug-98424-4@http.gcc.gnu.org/bugzilla/> (raw)
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
next reply other threads:[~2020-12-23 3:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-23 3:01 xmh970252187 at gmail dot com [this message]
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
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-98424-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: link
Be 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).