Commit fc7721ee by Paolo Carlini

re PR c++/53903 ([C++11] Incompatible exception-specification allowed if member…

re PR c++/53903 ([C++11] Incompatible exception-specification allowed if member explicitly-defaulted after first declaration)

/cp
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.

/testsuite
2013-05-14  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53903
	* g++.dg/cpp0x/defaulted43.C: New.

From-SVN: r198886
parent dd787b0c
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> 2013-05-14 Jason Merrill <jason@redhat.com>
PR c++/56998 PR c++/56998
......
...@@ -1755,6 +1755,7 @@ defaulted_late_check (tree fn) ...@@ -1755,6 +1755,7 @@ defaulted_late_check (tree fn)
bool fn_const_p = (copy_fn_p (fn) == 2); bool fn_const_p = (copy_fn_p (fn) == 2);
tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p, tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
NULL, NULL); NULL, NULL);
tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)), if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
TREE_TYPE (TREE_TYPE (implicit_fn))) TREE_TYPE (TREE_TYPE (implicit_fn)))
...@@ -1766,31 +1767,40 @@ defaulted_late_check (tree fn) ...@@ -1766,31 +1767,40 @@ defaulted_late_check (tree fn)
"does not match expected signature %qD", implicit_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 implicitly considered to have the same exception-specification as if
it had been implicitly declared. */ 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)); maybe_instantiate_noexcept (fn);
if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))) if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)),
eh_spec, ce_normal))
{ {
maybe_instantiate_noexcept (fn); if (DECL_DEFAULTED_IN_CLASS_P (fn))
if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)),
eh_spec, ce_normal))
error ("function %q+D defaulted on its first declaration " error ("function %q+D defaulted on its first declaration "
"with an exception-specification that differs from " "with an exception-specification that differs from "
"the implicit declaration %q#D", fn, implicit_fn); "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)) if (DECL_DEFAULTED_IN_CLASS_P (fn))
{ TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
/* Hmm...should we do this for out-of-class too? Should it be OK to
add constexpr later like inline, rather than requiring if (DECL_DEFAULTED_IN_CLASS_P (fn)
declarations to match? */ && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
DECL_DECLARED_CONSTEXPR_P (fn) = true; {
if (kind == sfk_constructor) /* Hmm...should we do this for out-of-class too? Should it be OK to
TYPE_HAS_CONSTEXPR_CTOR (ctx) = true; 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) if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
......
2013-05-14 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53903
* g++.dg/cpp0x/defaulted43.C: New.
2013-05-14 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> 2013-05-14 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* gcc.dg/fstack-protector-strong.c: Don't include <stdlib.h>. * gcc.dg/fstack-protector-strong.c: Don't include <stdlib.h>.
...@@ -6,7 +11,7 @@ ...@@ -6,7 +11,7 @@
2013-05-14 Joern Rennecke <joern.rennecke@embecosm.com> 2013-05-14 Joern Rennecke <joern.rennecke@embecosm.com>
* testsuite/gcc.c-torture/compile/limits-externdecl.c [target avr-*-*]: * gcc.c-torture/compile/limits-externdecl.c [target avr-*-*]:
Expect "size of array is too large" error. Expect "size of array is too large" error.
2013-05-14 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> 2013-05-14 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
......
// PR c++/53903
// { dg-do compile { target c++11 } }
struct T
{
T() noexcept(false) { }
~T() noexcept(false) { }
};
struct A
{
A() noexcept;
~A() noexcept;
T t;
};
A::A() noexcept = default; // { dg-error "defaulted" }
A::~A() noexcept = default; // { dg-error "defaulted" }
struct U
{
U() noexcept(false) { }
~U() noexcept(false) { }
};
struct B
{
B() noexcept(false);
~B() noexcept(false);
U u;
};
B::B() noexcept(false) = default;
B::~B() noexcept(false) = default;
struct V
{
V() noexcept(false) { }
~V() noexcept(false) { }
};
struct C
{
C() noexcept = default; // { dg-error "defaulted" }
~C() noexcept = default; // { dg-error "defaulted" }
V v;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment