diff options
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/method.c | 44 |
2 files changed, 33 insertions, 17 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index aca1ece1010..9c09c134c47 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-05-14 Paolo Carlini <paolo.carlini@oracle.com> + + PR c++/53903 + * method.c (defaulted_late_check): Check for compatible exception + specification out of class explicitly defaulted functions too. + 2013-05-14 Jason Merrill <jason@redhat.com> PR c++/56998 diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 316c5d3b8eb..801b3a5422a 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1755,6 +1755,7 @@ defaulted_late_check (tree fn) bool fn_const_p = (copy_fn_p (fn) == 2); tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p, NULL, NULL); + tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn)); if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)), TREE_TYPE (TREE_TYPE (implicit_fn))) @@ -1766,31 +1767,40 @@ defaulted_late_check (tree fn) "does not match expected signature %qD", implicit_fn); } - /* 8.4.2/2: If it is explicitly defaulted on its first declaration, it is + /* 8.4.2/2: An explicitly-defaulted function (...) may have an explicit + exception-specification only if it is compatible (15.4) with the + exception-specification on the implicit declaration. If a function + is explicitly defaulted on its first declaration, (...) it is implicitly considered to have the same exception-specification as if it had been implicitly declared. */ - if (DECL_DEFAULTED_IN_CLASS_P (fn)) + if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))) { - tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn)); - if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))) + maybe_instantiate_noexcept (fn); + if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)), + eh_spec, ce_normal)) { - maybe_instantiate_noexcept (fn); - if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (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); + else + error ("function %q+D defaulted on its redeclaration " + "with an exception-specification that differs from " + "the implicit declaration %q#D", fn, implicit_fn); } - TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec); - if (DECL_DECLARED_CONSTEXPR_P (implicit_fn)) - { - /* Hmm...should we do this for out-of-class too? Should it be OK to - add constexpr later like inline, rather than requiring - declarations to match? */ - DECL_DECLARED_CONSTEXPR_P (fn) = true; - if (kind == sfk_constructor) - TYPE_HAS_CONSTEXPR_CTOR (ctx) = true; - } + } + if (DECL_DEFAULTED_IN_CLASS_P (fn)) + TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec); + + if (DECL_DEFAULTED_IN_CLASS_P (fn) + && DECL_DECLARED_CONSTEXPR_P (implicit_fn)) + { + /* Hmm...should we do this for out-of-class too? Should it be OK to + add constexpr later like inline, rather than requiring + declarations to match? */ + DECL_DECLARED_CONSTEXPR_P (fn) = true; + if (kind == sfk_constructor) + TYPE_HAS_CONSTEXPR_CTOR (ctx) = true; } if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn) |