2011-03-25 Jason Merrill <jason@redhat.com>
+ Core 1135
+ * method.c (defaulted_late_check): Check for exception spec mismatch.
+ (defaultable_fn_check): Allow exception spec and virtual.
+ * class.c (check_for_override): A virtual dtor is non-trivial.
+
PR c++/48289
* pt.c (build_non_dependent_expr): Keep dereferences outside the
NON_DEPENDENT_EXPR.
if (!DECL_VINDEX (decl))
DECL_VINDEX (decl) = error_mark_node;
IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
+ if (DECL_DESTRUCTOR_P (decl))
+ TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
}
}
if (DECL_DEFAULTED_IN_CLASS_P (fn))
{
tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
+ if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))
+ && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)),
+ eh_spec, ce_normal))
+ error ("function %q+D defaulted on its first declaration "
+ "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
break;
}
if (TYPE_BEING_DEFINED (DECL_CONTEXT (fn)))
- {
- if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
- error ("function %q+D defaulted on its first declaration "
- "must not have an exception-specification", fn);
- if (DECL_VIRTUAL_P (fn))
- error ("%qD declared virtual cannot be defaulted in the class "
- "body", fn);
- }
+ /* Defer checking. */;
else if (!processing_template_decl)
defaulted_late_check (fn);
+2011-03-25 Jason Merrill <jason@redhat.com>
+
+ * g++.dg/cpp0x/defaulted22.C: New.
+ * g++.dg/cpp0x/defaulted23.C: New.
+ * g++.dg/cpp0x/defaulted15.C: Adjust.
+
2011-03-25 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/move1.C: New.
struct H
{
- virtual ~H() = default; // { dg-error "declared virtual" }
+ virtual ~H() = default;
};
--- /dev/null
+// Test that a virtual defaulted constructor is still virtual.
+// { dg-do run }
+// { dg-options -std=c++0x }
+
+int r = 1;
+
+struct A
+{
+ virtual ~A() = default;
+};
+
+struct B: A
+{
+ ~B() noexcept { r = 0; }
+};
+
+A* ap = new B();
+
+int main()
+{
+ delete ap;
+ return r;
+}
--- /dev/null
+// Test for checking of exception specifications on defaulted fns
+// { dg-options -std=c++0x }
+
+struct A
+{
+ A() noexcept = default;
+};
+
+struct B
+{
+ B() throw (int) = default; // { dg-error "exception-specification that differs from the implicit declaration" }
+};
+
+struct C
+{
+ C() throw (int) { }
+};
+
+struct D: C
+{
+ D() throw (int) = default;
+};
+
+struct E
+{
+ E() = default;
+};