Bug 50043 - [C++0x] Implement core/1123
Summary: [C++0x] Implement core/1123
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 51295 53613 61067 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-08-11 09:23 UTC by Paolo Carlini
Modified: 2014-05-05 15:23 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-03-23 00:00:00


Attachments
A testcase for N3204 (167 bytes, application/octet-stream)
2012-02-21 11:51 UTC, Michel Morin
Details
A updated testcase (324 bytes, application/octet-stream)
2012-02-22 02:43 UTC, Michel Morin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paolo Carlini 2011-08-11 09:23:21 UTC
... let's try this new Bugzilla ;)

This is an internal reminder that it would be nice to have implemented quite soon the resolution of core/1123:

  http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1123

For sure the library would immediately benefit, no more explicitly noexcept destructors in a lot of places.
Comment 1 Michel Morin 2012-02-21 11:51:14 UTC
Created attachment 26711 [details]
A testcase for N3204

Attached a testcase for N3204 ;)
Comment 2 Jonathan Wakely 2012-02-21 12:05:40 UTC
We don't want front-end testcases that rely on <iostream> and need to check what gets printed. A better test would use static_assert, but would also test cases with both throwing and non-throwing base class and members.
Comment 3 Michel Morin 2012-02-22 02:43:30 UTC
Created attachment 26721 [details]
A updated testcase

OK, here is a take two!
Comment 4 Paolo Carlini 2012-03-23 01:05:26 UTC
Jason, I'm glad to work on this (if you don't have anything better to do ;) Any tips for me? Shouldn't be so hard but I'm still a bit lost...
Comment 5 Paolo Carlini 2012-03-23 01:07:00 UTC
Of course I meant "if you have something better to do ;)"
Comment 6 Paolo Carlini 2012-03-23 17:59:05 UTC
I'm making some progress understanding these parts of the front-end.

For example the following trivial patchlet passes the testcase ;) But, seriously, I'm not sure whether we really need a full fledged build_exception_variant, whether we have to do something about LAZY_* things, and much, much, more.


Index: class.c
===================================================================
--- class.c     (revision 185722)
+++ class.c     (working copy)
@@ -1001,6 +1001,10 @@ add_method (tree type, tree method, tree using_dec
                   "destructor",
                   type);
        }
+      else if (cxx_dialect >= cxx0x
+              && !TYPE_RAISES_EXCEPTIONS (TREE_TYPE (method)))
+       TREE_TYPE (method) = build_exception_variant (TREE_TYPE (method),
+                                                     noexcept_true_spec);
     }
   else
     {
Comment 7 Paolo Carlini 2012-03-23 18:17:56 UTC
This doesn't compile, for example:

struct B
{
  ~B();
};

B::~B() { }
Comment 8 Paolo Carlini 2012-03-23 22:48:59 UTC
The latter issue could be addressed by something like:

Index: decl.c
===================================================================
--- decl.c	(revision 185715)
+++ decl.c	(working copy)
@@ -1136,7 +1136,10 @@ check_redeclaration_exception_specification (tree
   if ((pedantic || ! DECL_IN_SYSTEM_HEADER (old_decl))
       && ! DECL_IS_BUILTIN (old_decl)
       && flag_exceptions
-      && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
+      && !comp_except_specs (new_exceptions, old_exceptions, ce_normal)
+      && !(DECL_DESTRUCTOR_P (new_decl)
+	   && cxx_dialect >= cxx0x
+	   && !new_exceptions && TYPE_NOEXCEPT_P (old_type)))	
     {
       error ("declaration of %qF has a different exception specifier",
 	     new_decl);
Comment 9 paolo@gcc.gnu.org 2012-04-02 00:13:35 UTC
Author: paolo
Date: Mon Apr  2 00:13:30 2012
New Revision: 186058

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186058
Log:
/cp
2012-04-01  Paolo Carlini  <paolo.carlini@oracle.com>

	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

/testsuite
2012-04-01  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/50043
	* g++.dg/cpp0x/noexcept17.C: New.
	* g++.old-deja/g++.eh/cleanup1.C: Adjust.
	* g++.dg/tree-ssa/ehcleanup-1.C: Likewise.
	* g++.dg/cpp0x/noexcept01.C: Likewise.
	* g++.dg/eh/init-temp1.C: Likewise.
	* g++.dg/eh/ctor1.C: Likwise.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/noexcept17.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/method.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/noexcept01.C
    trunk/gcc/testsuite/g++.dg/eh/ctor1.C
    trunk/gcc/testsuite/g++.dg/eh/init-temp1.C
    trunk/gcc/testsuite/g++.dg/tree-ssa/ehcleanup-1.C
    trunk/gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C
Comment 10 Paolo Carlini 2012-04-02 00:19:43 UTC
Done. Library clean-ups will follow.
Comment 11 Paolo Carlini 2012-04-12 00:10:26 UTC
*** Bug 51295 has been marked as a duplicate of this bug. ***
Comment 12 Jonathan Wakely 2012-06-11 10:28:40 UTC
*** Bug 53613 has been marked as a duplicate of this bug. ***
Comment 13 Kirby Zhou 2012-06-13 03:48:34 UTC
How about back port this patch to 4.7 branch?
It cause a lot of compile error which easily confuse programmers.


(In reply to comment #9)
> Author: paolo
> Date: Mon Apr  2 00:13:30 2012
> New Revision: 186058
> 
> URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186058
> Log:
> /cp
> 2012-04-01  Paolo Carlini  <paolo.carlini@oracle.com>
> 
>     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
> 
> /testsuite
> 2012-04-01  Paolo Carlini  <paolo.carlini@oracle.com>
> 
>     PR c++/50043
>     * g++.dg/cpp0x/noexcept17.C: New.
>     * g++.old-deja/g++.eh/cleanup1.C: Adjust.
>     * g++.dg/tree-ssa/ehcleanup-1.C: Likewise.
>     * g++.dg/cpp0x/noexcept01.C: Likewise.
>     * g++.dg/eh/init-temp1.C: Likewise.
>     * g++.dg/eh/ctor1.C: Likwise.
> 
> Added:
>     trunk/gcc/testsuite/g++.dg/cpp0x/noexcept17.C
> Modified:
>     trunk/gcc/cp/ChangeLog
>     trunk/gcc/cp/class.c
>     trunk/gcc/cp/cp-tree.h
>     trunk/gcc/cp/decl.c
>     trunk/gcc/cp/method.c
>     trunk/gcc/testsuite/ChangeLog
>     trunk/gcc/testsuite/g++.dg/cpp0x/noexcept01.C
>     trunk/gcc/testsuite/g++.dg/eh/ctor1.C
>     trunk/gcc/testsuite/g++.dg/eh/init-temp1.C
>     trunk/gcc/testsuite/g++.dg/tree-ssa/ehcleanup-1.C
>     trunk/gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C
Comment 14 Kirby Zhou 2012-06-15 02:14:48 UTC
I have tested to apply this patch to 4.7 branch, everythings goes well.
Since it breaks already existing code, anybody can do commit backport to 4.7 branch?

(In reply to comment #13)
> How about back port this patch to 4.7 branch?
> It cause a lot of compile error which easily confuse programmers.
> (In reply to comment #9)
> > Author: paolo
> > Date: Mon Apr  2 00:13:30 2012
> > New Revision: 186058
> > 
> > URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186058
> > Log:
> > /cp
> > 2012-04-01  Paolo Carlini  <paolo.carlini@oracle.com>
> > 
> >     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
> > 
> > /testsuite
> > 2012-04-01  Paolo Carlini  <paolo.carlini@oracle.com>
> > 
> >     PR c++/50043
> >     * g++.dg/cpp0x/noexcept17.C: New.
> >     * g++.old-deja/g++.eh/cleanup1.C: Adjust.
> >     * g++.dg/tree-ssa/ehcleanup-1.C: Likewise.
> >     * g++.dg/cpp0x/noexcept01.C: Likewise.
> >     * g++.dg/eh/init-temp1.C: Likewise.
> >     * g++.dg/eh/ctor1.C: Likwise.
> > 
> > Added:
> >     trunk/gcc/testsuite/g++.dg/cpp0x/noexcept17.C
> > Modified:
> >     trunk/gcc/cp/ChangeLog
> >     trunk/gcc/cp/class.c
> >     trunk/gcc/cp/cp-tree.h
> >     trunk/gcc/cp/decl.c
> >     trunk/gcc/cp/method.c
> >     trunk/gcc/testsuite/ChangeLog
> >     trunk/gcc/testsuite/g++.dg/cpp0x/noexcept01.C
> >     trunk/gcc/testsuite/g++.dg/eh/ctor1.C
> >     trunk/gcc/testsuite/g++.dg/eh/init-temp1.C
> >     trunk/gcc/testsuite/g++.dg/tree-ssa/ehcleanup-1.C
> >     trunk/gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C
Comment 15 Jonathan Wakely 2014-05-05 15:23:59 UTC
*** Bug 61067 has been marked as a duplicate of this bug. ***