diff options
author | Jason Merrill <jason@redhat.com> | 2013-10-23 15:16:37 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2013-10-23 15:16:37 -0400 |
commit | e2fbf4c53d5ebe7638695797671dcef927cd73d7 (patch) | |
tree | 11fd15b0df7169b1fc707ebcb47bb2b102072e22 | |
parent | 3f04b1bb6b124028008630fd791cdbd38925470c (diff) | |
download | gcc-e2fbf4c53d5ebe7638695797671dcef927cd73d7.zip gcc-e2fbf4c53d5ebe7638695797671dcef927cd73d7.tar.gz gcc-e2fbf4c53d5ebe7638695797671dcef927cd73d7.tar.bz2 |
LWG 2165
LWG 2165
* method.c (defaulted_late_check): Delete on eh-spec mismatch.
(maybe_explain_implicit_delete): Explain it.
From-SVN: r203989
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/method.c | 36 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/defaulted23.C | 12 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/defaulted43.C | 14 |
4 files changed, 56 insertions, 10 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 78721a3..123200b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-10-23 Jason Merrill <jason@redhat.com> + LWG 2165 + * method.c (defaulted_late_check): Delete on eh-spec mismatch. + (maybe_explain_implicit_delete): Explain it. + * error.c (eh_spec_to_string): New. (cp_printer): Use it for %X. diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 593a4a6..594a004 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1466,13 +1466,34 @@ maybe_explain_implicit_delete (tree decl) tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl); tree parm_type = TREE_VALUE (parms); bool const_p = CP_TYPE_CONST_P (non_reference (parm_type)); + tree raises = NULL_TREE; + bool deleted_p = false; tree scope = push_scope (ctype); - inform (0, "%q+#D is implicitly deleted because the default " - "definition would be ill-formed:", decl); - pop_scope (scope); + synthesized_method_walk (ctype, sfk, const_p, - NULL, NULL, NULL, NULL, true, + &raises, NULL, &deleted_p, NULL, false, DECL_INHERITED_CTOR_BASE (decl), parms); + if (deleted_p) + { + inform (0, "%q+#D is implicitly deleted because the default " + "definition would be ill-formed:", decl); + synthesized_method_walk (ctype, sfk, const_p, + NULL, NULL, NULL, NULL, true, + DECL_INHERITED_CTOR_BASE (decl), parms); + } + else if (!comp_except_specs + (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)), + raises, ce_normal)) + inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly " + "deleted because its exception-specification does not " + "match the implicit exception-specification %qX", + decl, raises); +#ifdef ENABLE_CHECKING + else + gcc_unreachable (); +#endif + + pop_scope (scope); } input_location = loc; @@ -1782,9 +1803,10 @@ defaulted_late_check (tree fn) eh_spec, ce_normal)) { if (DECL_DEFAULTED_IN_CLASS_P (fn)) - error ("function %q+D defaulted on its first declaration " - "with an exception-specification that differs from " - "the implicit declaration %q#D", fn, implicit_fn); + { + DECL_DELETED_FN (fn) = true; + eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)); + } else error ("function %q+D defaulted on its redeclaration " "with an exception-specification that differs from " diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted23.C b/gcc/testsuite/g++.dg/cpp0x/defaulted23.C index 319cb39..be2fd2f 100644 --- a/gcc/testsuite/g++.dg/cpp0x/defaulted23.C +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted23.C @@ -6,22 +6,32 @@ struct A A() noexcept = default; }; +A a; + struct B { - B() throw (int) = default; // { dg-error "exception-specification that differs from the implicit declaration" } + B() throw (int) = default; // { dg-message "exception-specification" } }; +B b; // { dg-error "deleted" } + struct C { C() throw (int) { } }; +C c; + struct D: C { D() throw (int) = default; }; +D d; + struct E { E() = default; }; + +E e; diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted43.C b/gcc/testsuite/g++.dg/cpp0x/defaulted43.C index e1c2b72..f2846fe 100644 --- a/gcc/testsuite/g++.dg/cpp0x/defaulted43.C +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted43.C @@ -7,6 +7,8 @@ struct T ~T() noexcept(false) { } }; +T t; + struct A { A() noexcept; @@ -24,6 +26,8 @@ struct U ~U() noexcept(false) { } }; +U u; + struct B { B() noexcept(false); @@ -35,16 +39,22 @@ struct B B::B() noexcept(false) = default; B::~B() noexcept(false) = default; +B b; + struct V { V() noexcept(false) { } ~V() noexcept(false) { } }; +V v; + struct C { - C() noexcept = default; // { dg-error "defaulted" } - ~C() noexcept = default; // { dg-error "defaulted" } + C() noexcept = default; // { dg-message "exception-specification" } + ~C() noexcept = default; // { dg-message "exception-specification" } V v; }; + +C c; // { dg-error "deleted" } |