summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-05-14 13:54:49 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-05-14 13:54:49 +0000
commit36ad1400910e2a8baabb1abcb8cee847aa6d0a7c (patch)
tree9dd4b06919cfff11739444ffb3b520b7762ad9c3
parent6c4553507f3f851523885d5fbef09de24b1e4be9 (diff)
downloadgcc-36ad1400910e2a8baabb1abcb8cee847aa6d0a7c.tar.gz
/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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@198886 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/method.c44
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted43.C50
4 files changed, 89 insertions, 18 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)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 966280ad9c2..0507b600058 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+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>
* gcc.dg/fstack-protector-strong.c: Don't include <stdlib.h>.
@@ -6,7 +11,7 @@
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.
2013-05-14 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted43.C b/gcc/testsuite/g++.dg/cpp0x/defaulted43.C
new file mode 100644
index 00000000000..e1c2b72ba27
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted43.C
@@ -0,0 +1,50 @@
+// 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;
+};