public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101442] New: Destructor not called for a temporary object, if it
@ 2021-07-13 18:17 iamsupermouse at mail dot ru
  2021-07-13 18:19 ` [Bug c++/101442] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO iamsupermouse at mail dot ru
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: iamsupermouse at mail dot ru @ 2021-07-13 18:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

            Bug ID: 101442
           Summary: Destructor not called for a temporary object, if it
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamsupermouse at mail dot ru
  Target Milestone: ---

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
@ 2021-07-13 18:19 ` iamsupermouse at mail dot ru
  2021-07-14  6:09 ` rguenth at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: iamsupermouse at mail dot ru @ 2021-07-13 18:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

--- Comment #1 from Egor <iamsupermouse at mail dot ru> ---
Example is provided below. It prints `A()` and nothing else. I expected it to
also pring `~A()`.

```
#include <iostream>

struct A
{
    A() {std::cout << "A()\n";}
    A(const A &) = delete;
    A &operator=(const A &) = delete;
    ~A() {std::cout << "~A()\n";}
};

struct B
{
    const A &a;
    std::string s;
};

B foo()
{
    B ret{ A{}, "" };
    return ret;
}

int main()
{
    B b = foo();
}
```

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
  2021-07-13 18:19 ` [Bug c++/101442] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO iamsupermouse at mail dot ru
@ 2021-07-14  6:09 ` rguenth at gcc dot gnu.org
  2021-07-14  9:39 ` [Bug c++/101442] [9/10/11/12 Regression] " redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-14  6:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-07-14
            Version|unknown                     |11.1.1
     Ever confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |10.3.1, 11.1.1, 12.0, 7.5.0
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  Works with clang.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9/10/11/12 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
  2021-07-13 18:19 ` [Bug c++/101442] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO iamsupermouse at mail dot ru
  2021-07-14  6:09 ` rguenth at gcc dot gnu.org
@ 2021-07-14  9:39 ` redi at gcc dot gnu.org
  2021-07-14  9:44 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-14  9:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.6.4
      Known to fail|                            |4.7.4
            Summary|Destructor not called for a |[9/10/11/12 Regression]
                   |temporary object, if it's   |Destructor not called for a
                   |bound to a ref member of an |temporary object, if it's
                   |object subject to NRVO      |bound to a ref member of an
                   |                            |object subject to NRVO

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Works correctly in GCC 4.6.4 too. I'll bisect.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9/10/11/12 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
                   ` (2 preceding siblings ...)
  2021-07-14  9:39 ` [Bug c++/101442] [9/10/11/12 Regression] " redi at gcc dot gnu.org
@ 2021-07-14  9:44 ` redi at gcc dot gnu.org
  2021-07-14  9:45 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-14  9:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The regression happened after r180941 and not after r180959. Almost certainly
this one, as it's the only C++ change in the range:

commit b25dd954c41bf75d2bc892c7e9114908eaa7d314
Author: Jason Merrill
Date:   Fri Nov 4 12:54:08 2011

    re PR c++/48370 (G++ fails to extend reference temporary lifetime in some
situations)

            PR c++/48370
            * call.c (extend_ref_init_temps, extend_ref_init_temps_1): New.
            (set_up_extended_ref_temp): Use it.  Change cleanup parm to VEC.
            (initialize_reference): Just call convert_like.
            * decl.c (grok_reference_init): Just call initialize_reference.
            (build_init_list_var_init): Remove.
            (check_initializer): Change cleanup parm to VEC.  Handle references
            like other types.  Call perform_implicit_conversion instead
            of build_init_list_var_init.  Don't use build_aggr_init for
            aggregate initialization of arrays.
            (cp_finish_decl): Change cleanup to VEC.
            * typeck2.c (store_init_value): Call extend_ref_init_temps.
            Use build_vec_init for non-constant arrays.
            * init.c (expand_aggr_init_1): Adjust.
            (build_vec_init): Avoid re-converting an initializer
            that's already digested.
            * mangle.c (mangle_ref_init_variable): Add a discriminator.
            * cp-tree.h: Adjust.
            * typeck.c (convert_for_initialization): Adjust.
            * decl2.c (maybe_emit_vtables): Adjust.

    From-SVN: r180944

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9/10/11/12 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
                   ` (3 preceding siblings ...)
  2021-07-14  9:44 ` redi at gcc dot gnu.org
@ 2021-07-14  9:45 ` redi at gcc dot gnu.org
  2021-07-19 11:49 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-14  9:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

bool destroyed = false;

struct A
{
    A() {}
    A(const A &) = delete;
    A &operator=(const A &) = delete;
    ~A() {destroyed = true;}
};

struct B
{
    const A &a;
    struct string {
     string(const char*) { }
    ~string() { }
    } s;
};

B foo()
{
    B ret{ A{}, "" };
    return ret;
}

int main()
{
  {
    B b = foo();
  }
  if (!destroyed)
    __builtin_abort();
}

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9/10/11/12 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
                   ` (4 preceding siblings ...)
  2021-07-14  9:45 ` redi at gcc dot gnu.org
@ 2021-07-19 11:49 ` rguenth at gcc dot gnu.org
  2022-04-13 16:13 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-19 11:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |9.5
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9/10/11/12 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
                   ` (5 preceding siblings ...)
  2021-07-19 11:49 ` rguenth at gcc dot gnu.org
@ 2022-04-13 16:13 ` jason at gcc dot gnu.org
  2022-04-14  0:24 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jason at gcc dot gnu.org @ 2022-04-13 16:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9/10/11/12 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
                   ` (6 preceding siblings ...)
  2022-04-13 16:13 ` jason at gcc dot gnu.org
@ 2022-04-14  0:24 ` cvs-commit at gcc dot gnu.org
  2022-05-13 16:28 ` [Bug c++/101442] [9/10/11 " cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-14  0:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:ad8161e6d7b26d690d90069ae9a129e7ac36892a

commit r12-8150-gad8161e6d7b26d690d90069ae9a129e7ac36892a
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 13 13:23:08 2022 -0400

    c++: NRV and ref-extended temps [PR101442]

    This issue goes back to r83221, where the cleanup for extended ref temps
    changed from being unconditional to being tied to the declaration they
    formed part of the initializer for.

    The named return value optimization changes the cleanup for the NRV
variable
    to only run on the EH path; we don't want that change to affect temporary
    cleanups.  The perform_member_init change isn't necessary (there 'decl' is
a
    COMPONENT_REF), it's just for consistency.

            PR c++/101442

    gcc/cp/ChangeLog:

            * decl.cc (cp_finish_decl): Don't pass decl to push_cleanup.
            * init.cc (perform_member_init): Likewise.
            * semantics.cc (push_cleanup): Adjust comment.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/initlist-nrv1.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9/10/11 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
                   ` (7 preceding siblings ...)
  2022-04-14  0:24 ` cvs-commit at gcc dot gnu.org
@ 2022-05-13 16:28 ` cvs-commit at gcc dot gnu.org
  2022-05-13 17:14 ` [Bug c++/101442] [9/10 " cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-13 16:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:f9e356458d8f14b5a82f3244385ce814903fc02b

commit r11-9995-gf9e356458d8f14b5a82f3244385ce814903fc02b
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 13 13:23:08 2022 -0400

    c++: NRV and ref-extended temps [PR101442]

    This issue goes back to r83221, where the cleanup for extended ref temps
    changed from being unconditional to being tied to the declaration they
    formed part of the initializer for.

    The named return value optimization changes the cleanup for the NRV
variable
    to only run on the EH path; we don't want that change to affect temporary
    cleanups.  The perform_member_init change isn't necessary (there 'decl' is
a
    COMPONENT_REF), it's just for consistency.

            PR c++/101442

    gcc/cp/ChangeLog:

            * decl.c (cp_finish_decl): Don't pass decl to push_cleanup.
            * init.c (perform_member_init): Likewise.
            * semantics.c (push_cleanup): Adjust comment.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/initlist-nrv1.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9/10 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
                   ` (8 preceding siblings ...)
  2022-05-13 16:28 ` [Bug c++/101442] [9/10/11 " cvs-commit at gcc dot gnu.org
@ 2022-05-13 17:14 ` cvs-commit at gcc dot gnu.org
  2022-05-13 17:41 ` [Bug c++/101442] [9 " cvs-commit at gcc dot gnu.org
  2022-05-13 17:51 ` jason at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-13 17:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:54d1992376d7880a88778dab20a7cfe8cde32bc3

commit r10-10736-g54d1992376d7880a88778dab20a7cfe8cde32bc3
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 13 13:23:08 2022 -0400

    c++: NRV and ref-extended temps [PR101442]

    This issue goes back to r83221, where the cleanup for extended ref temps
    changed from being unconditional to being tied to the declaration they
    formed part of the initializer for.

    The named return value optimization changes the cleanup for the NRV
variable
    to only run on the EH path; we don't want that change to affect temporary
    cleanups.  The perform_member_init change isn't necessary (there 'decl' is
a
    COMPONENT_REF), it's just for consistency.

            PR c++/101442

    gcc/cp/ChangeLog:

            * decl.c (cp_finish_decl): Don't pass decl to push_cleanup.
            * init.c (perform_member_init): Likewise.
            * semantics.c (push_cleanup): Adjust comment.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/initlist-nrv1.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
                   ` (9 preceding siblings ...)
  2022-05-13 17:14 ` [Bug c++/101442] [9/10 " cvs-commit at gcc dot gnu.org
@ 2022-05-13 17:41 ` cvs-commit at gcc dot gnu.org
  2022-05-13 17:51 ` jason at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-13 17:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:48b8d5e028abee8869de946bbd7d24d746655d88

commit r9-10173-g48b8d5e028abee8869de946bbd7d24d746655d88
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 13 13:23:08 2022 -0400

    c++: NRV and ref-extended temps [PR101442]

    This issue goes back to r83221, where the cleanup for extended ref temps
    changed from being unconditional to being tied to the declaration they
    formed part of the initializer for.

    The named return value optimization changes the cleanup for the NRV
variable
    to only run on the EH path; we don't want that change to affect temporary
    cleanups.  The perform_member_init change isn't necessary (there 'decl' is
a
    COMPONENT_REF), it's just for consistency.

            PR c++/101442

    gcc/cp/ChangeLog:

            * decl.c (cp_finish_decl): Don't pass decl to push_cleanup.
            * init.c (perform_member_init): Likewise.
            * semantics.c (push_cleanup): Adjust comment.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/initlist-nrv1.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/101442] [9 Regression] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO
  2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
                   ` (10 preceding siblings ...)
  2022-05-13 17:41 ` [Bug c++/101442] [9 " cvs-commit at gcc dot gnu.org
@ 2022-05-13 17:51 ` jason at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jason at gcc dot gnu.org @ 2022-05-13 17:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101442

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #10 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 9.5/10.4/11.4/12.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-05-13 17:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 18:17 [Bug c++/101442] New: Destructor not called for a temporary object, if it iamsupermouse at mail dot ru
2021-07-13 18:19 ` [Bug c++/101442] Destructor not called for a temporary object, if it's bound to a ref member of an object subject to NRVO iamsupermouse at mail dot ru
2021-07-14  6:09 ` rguenth at gcc dot gnu.org
2021-07-14  9:39 ` [Bug c++/101442] [9/10/11/12 Regression] " redi at gcc dot gnu.org
2021-07-14  9:44 ` redi at gcc dot gnu.org
2021-07-14  9:45 ` redi at gcc dot gnu.org
2021-07-19 11:49 ` rguenth at gcc dot gnu.org
2022-04-13 16:13 ` jason at gcc dot gnu.org
2022-04-14  0:24 ` cvs-commit at gcc dot gnu.org
2022-05-13 16:28 ` [Bug c++/101442] [9/10/11 " cvs-commit at gcc dot gnu.org
2022-05-13 17:14 ` [Bug c++/101442] [9/10 " cvs-commit at gcc dot gnu.org
2022-05-13 17:41 ` [Bug c++/101442] [9 " cvs-commit at gcc dot gnu.org
2022-05-13 17:51 ` jason 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).