public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94616] New: Incorrect destruction for partially built objects
@ 2020-04-16  9:58 stephane.zimmermann@trust-in-soft.com
  2020-04-16 10:07 ` [Bug c++/94616] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: stephane.zimmermann@trust-in-soft.com @ 2020-04-16  9:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94616
           Summary: Incorrect destruction for partially built objects
           Product: gcc
           Version: 7.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stephane.zimmermann@trust-in-soft.com
  Target Milestone: ---

Created attachment 48286
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48286&action=edit
Test file

With the attached file "test.cpp":

extern "C" int printf(const char *, ...);

struct Bar {
    Bar(int n) {
        printf("Bar(%d)\n", n);
        if (n > 0)
            throw 2;
    }

    ~Bar() { printf("~Bar\n"); }
};

struct Foo {
    Bar b1 = 0;
    Bar b2 = 1;
    Foo() { }

    ~Foo() { printf("~Foo()"); }
};

int
main()
{
    try {
        Foo f;
    } catch(int) {
        printf("catch\n");
    }
}

Compiling and running the program yields:
$ g++ test.cpp -fexceptions -std=c++11 && ./a.out
Bar(0)
Bar(1)
terminate called after throwing an instance of 'int'
Aborted (core dumped)

I expected this output:
Bar(0)
Bar(1)
~Bar
catch

As a consequence of n3337[except.ctor]p2:
An object of any storage duration whose initialization or destruction is
terminated by an exception will have destructors executed for all of its fully
constructed subobjects (excluding the variant members of a union-like class),
that is, for subobjects for which the principal constructor ([class.base.init])
has completed execution and the destructor has not yet begun execution.

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

* [Bug c++/94616] Incorrect destruction for partially built objects
  2020-04-16  9:58 [Bug c++/94616] New: Incorrect destruction for partially built objects stephane.zimmermann@trust-in-soft.com
@ 2020-04-16 10:07 ` redi at gcc dot gnu.org
  2020-04-16 10:16 ` [Bug c++/94616] [8 Regression] " redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-16 10:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
           Keywords|                            |wrong-code
         Resolution|---                         |DUPLICATE
   Target Milestone|---                         |9.0

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
GCC 7 is no longer supported, and this has already been fixed in GCC 9.

*** This bug has been marked as a duplicate of bug 85363 ***

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

* [Bug c++/94616] [8 Regression] Incorrect destruction for partially built objects
  2020-04-16  9:58 [Bug c++/94616] New: Incorrect destruction for partially built objects stephane.zimmermann@trust-in-soft.com
  2020-04-16 10:07 ` [Bug c++/94616] " redi at gcc dot gnu.org
@ 2020-04-16 10:16 ` redi at gcc dot gnu.org
  2020-04-16 10:16 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-16 10:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|RESOLVED                    |NEW
   Last reconfirmed|                            |2020-04-16
         Resolution|DUPLICATE                   |---
            Summary|Incorrect destruction for   |[8 Regression] Incorrect
                   |partially built objects     |destruction for partially
                   |                            |built objects
      Known to work|                            |4.7.4, 9.1.0
      Known to fail|                            |4.8.5, 4.9.4, 5.5.0, 6.5.0,
                   |                            |7.5.0, 8.4.0

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Although it was fixed by r260300 it doesn't seem to be an exact dup of PR 85363
because this one is a regression since 4.7 and fails consistently with C++11
and C++14.

Reopening, because we should consider backporting r260300 to gcc-8.

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

* [Bug c++/94616] [8 Regression] Incorrect destruction for partially built objects
  2020-04-16  9:58 [Bug c++/94616] New: Incorrect destruction for partially built objects stephane.zimmermann@trust-in-soft.com
  2020-04-16 10:07 ` [Bug c++/94616] " redi at gcc dot gnu.org
  2020-04-16 10:16 ` [Bug c++/94616] [8 Regression] " redi at gcc dot gnu.org
@ 2020-04-16 10:16 ` redi at gcc dot gnu.org
  2020-04-16 10:30 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-16 10:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
   Target Milestone|9.0                         |8.5

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

* [Bug c++/94616] [8 Regression] Incorrect destruction for partially built objects
  2020-04-16  9:58 [Bug c++/94616] New: Incorrect destruction for partially built objects stephane.zimmermann@trust-in-soft.com
                   ` (2 preceding siblings ...)
  2020-04-16 10:16 ` redi at gcc dot gnu.org
@ 2020-04-16 10:30 ` redi at gcc dot gnu.org
  2020-04-16 10:52 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-16 10:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The regression started with Paolo's r186058:

    re PR c++/50043 ([C++0x] Implement core/1123)

            PR c++/50043
            * class.c (deduce_noexcept_on_destructor,
            deduce_noexcept_on_destructors): New.
            (check_bases_and_members): Call the latter.
            * decl.c (grokfndecl): Call the former.
            * method.c (implicitly_declare_fn): Not static.
            * cp-tree.h (deduce_noexcept_on_destructor, implicitly_declare_fn):
            Declare

For gcc-4.8 and gcc-4.9 using -fPIC makes it pass, but then since gcc-5 it
fails even with -fPIC, due to Jason's r213307:

    re PR lto/53808 (Undefined symbol when building a library with lto)

            PR lto/53808
            PR c++/61659
            * pt.c (push_template_decl_real): Set DECL_COMDAT on templates.
            (check_explicit_specialization): Clear it on specializations.
            * decl.c (duplicate_decls, start_decl): Likewise.
            (grokmethod, grokfndecl): Set DECL_COMDAT on inlines.
            * method.c (implicitly_declare_fn): Set DECL_COMDAT.  Determine
            linkage after setting the appropriate flags.
            * tree.c (decl_linkage): Don't check DECL_COMDAT.
            * decl2.c (mark_needed): Mark clones.
            (import_export_decl): Not here.

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

* [Bug c++/94616] [8 Regression] Incorrect destruction for partially built objects
  2020-04-16  9:58 [Bug c++/94616] New: Incorrect destruction for partially built objects stephane.zimmermann@trust-in-soft.com
                   ` (3 preceding siblings ...)
  2020-04-16 10:30 ` redi at gcc dot gnu.org
@ 2020-04-16 10:52 ` jakub at gcc dot gnu.org
  2021-05-14 13:36 ` cvs-commit at gcc dot gnu.org
  2021-05-14 13:36 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-04-16 10:52 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #2)
> Although it was fixed by r260300 it doesn't seem to be an exact dup of PR
> 85363 because this one is a regression since 4.7 and fails consistently with
> C++11 and C++14.

So, do we want the testcase into the testsuite then to verify we don't regress
it again?

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

* [Bug c++/94616] [8 Regression] Incorrect destruction for partially built objects
  2020-04-16  9:58 [Bug c++/94616] New: Incorrect destruction for partially built objects stephane.zimmermann@trust-in-soft.com
                   ` (4 preceding siblings ...)
  2020-04-16 10:52 ` jakub at gcc dot gnu.org
@ 2021-05-14 13:36 ` cvs-commit at gcc dot gnu.org
  2021-05-14 13:36 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-14 13:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:3cafe627d6c8bce7e7f46bdbdef3d14e9701ce9d

commit r12-800-g3cafe627d6c8bce7e7f46bdbdef3d14e9701ce9d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri May 14 15:34:12 2021 +0200

    testsuite: Add testcase for already fixed PR [PR94616]

    2021-05-14  Jakub Jelinek  <jakub@redhat.com>

            PR c++/94616
            * g++.dg/cpp0x/pr94616.C: New test.

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

* [Bug c++/94616] [8 Regression] Incorrect destruction for partially built objects
  2020-04-16  9:58 [Bug c++/94616] New: Incorrect destruction for partially built objects stephane.zimmermann@trust-in-soft.com
                   ` (5 preceding siblings ...)
  2021-05-14 13:36 ` cvs-commit at gcc dot gnu.org
@ 2021-05-14 13:36 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-05-14 13:36 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|8.5                         |9.0
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The GCC 8 branch is being closed, fixed in GCC 9.1.

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

end of thread, other threads:[~2021-05-14 13:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-16  9:58 [Bug c++/94616] New: Incorrect destruction for partially built objects stephane.zimmermann@trust-in-soft.com
2020-04-16 10:07 ` [Bug c++/94616] " redi at gcc dot gnu.org
2020-04-16 10:16 ` [Bug c++/94616] [8 Regression] " redi at gcc dot gnu.org
2020-04-16 10:16 ` redi at gcc dot gnu.org
2020-04-16 10:30 ` redi at gcc dot gnu.org
2020-04-16 10:52 ` jakub at gcc dot gnu.org
2021-05-14 13:36 ` cvs-commit at gcc dot gnu.org
2021-05-14 13:36 ` jakub 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).