public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ RFC / Patch] Implementing "Deducing "noexcept" for destructors"
@ 2012-03-26 11:25 Paolo Carlini
  2012-03-26 19:31 ` Jason Merrill
  0 siblings, 1 reply; 17+ messages in thread
From: Paolo Carlini @ 2012-03-26 11:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[sorry, I'm resending this because inadvertently I had some html and the 
message got rejected]

Hi,

thus, I have been working on c++/50043, which boils down to this:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3204.htm

My basic idea so far is very simple:

--- class.c (revision 185792)
+++ 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
{

thus, right before actually adding the method we check whether nothing 
has been deduced about it and we enforce the default noexcept. It's 
already enough to cover the testcase provided in c++/50043, which 
includes a good range of positive and negative tests. Does the idea make 
sense? As is, the patchlet leads to a few regressions, largely benign as 
far as I can see:

FAIL: g++.dg/cpp0x/noexcept01.C (test for excess errors)
FAIL: g++.dg/eh/ctor1.C -std=c++11 execution test
FAIL: g++.dg/eh/init-temp1.C -std=c++11 execution test
FAIL: g++.dg/tree-ssa/ehcleanup-1.C -std=gnu++11 scan-tree-dump-times 
ehcleanup1 "Removing unreachable" 4
FAIL: g++.old-deja/g++.eh/cleanup1.C -std=c++11 execution test

(the idea would changing the tests to be c++98 only and then adding 
c++11 counterparts)

Something the patchlet does not cover is:

struct B
{ ~B(); };

B::~B() { }

<mailto:paolo.carlini@oracle.com>
indeed the "as an implicit declaration" bits of the new wording in C++11 
doesn't guide so much about this, I guess it means something like:

--- decl.c (revision 185792)
+++ decl.c (working copy)
@@ -1144,7 +1144,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);

does it make sense?

Another case which makes me nervous is when we add to the testcase in 
c++/50043 also a case for a virtual base class destructor, thus 
something like

struct True2 { virtual ~True2(); };
struct False { ~False() noexcept(false); };

template <typename Base, typename Member>
struct C : Base
{
Member mem;
};

SA(!noexcept(C<True2, False>()));

it doesn't compile at all because:

noexcept_PR50043.C:21:8: error: looser throw specifier for ‘virtual 
C<True2, False>::~C() noexcept (false)Â’
noexcept_PR50043.C:5:24: error: overriding ‘virtual True2::~True2() 
noexcept (true)Â’

is this expected? Maybe, but I'm not sure.

Thanks in advance for any tips!
Paolo.

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

end of thread, other threads:[~2012-04-02  0:17 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-26 11:25 [C++ RFC / Patch] Implementing "Deducing "noexcept" for destructors" Paolo Carlini
2012-03-26 19:31 ` Jason Merrill
2012-03-26 23:08   ` Paolo Carlini
2012-03-28 15:06   ` Paolo Carlini
2012-03-28 15:18     ` Jason Merrill
2012-03-28 22:44       ` Paolo Carlini
2012-03-28 22:47         ` Paolo Carlini
2012-03-29 15:18           ` Paolo Carlini
2012-03-29 18:51         ` Jason Merrill
2012-03-29 19:10           ` Paolo Carlini
2012-03-29 19:23             ` Paolo Carlini
2012-03-29 19:27             ` Jason Merrill
2012-03-29 19:37               ` Paolo Carlini
2012-03-29 22:30               ` Paolo Carlini
2012-03-31  1:38                 ` Paolo Carlini
2012-04-01 18:26                   ` Jason Merrill
2012-04-02  0:17                     ` Paolo Carlini

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).