2014-07-13 Jason Merrill <jason@redhat.com>
+ PR c++/58511
+ * semantics.c (is_instantiation_of_constexpr): Return true for
+ defaulted functions, too.
+ (explain_invalid_constexpr_fn): Only use
+ explain_implicit_non_constexpr if !DECL_DECLARED_CONSTEXPR_P.
+ * method.c (explain_implicit_non_constexpr): Pass
+ DECL_INHERITED_CTOR_BASE to explain_implicit_non_constexpr.
+
PR c++/58611
* decl.c (check_initializer): Don't finish_compound_literal
on erroneous constexpr init.
synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
special_function_p (decl), const_p,
NULL, NULL, NULL, &dummy, true,
- NULL_TREE, NULL_TREE);
+ DECL_INHERITED_CTOR_BASE (decl),
+ FUNCTION_FIRST_USER_PARMTYPE (decl));
}
/* DECL is an instantiation of an inheriting constructor template. Deduce
}
/* Returns true iff FUN is an instantiation of a constexpr function
- template. */
+ template or a defaulted constexpr function. */
static inline bool
is_instantiation_of_constexpr (tree fun)
{
- return (DECL_TEMPLOID_INSTANTIATION (fun)
- && DECL_DECLARED_CONSTEXPR_P (DECL_TI_TEMPLATE (fun)));
+ return ((DECL_TEMPLOID_INSTANTIATION (fun)
+ && DECL_DECLARED_CONSTEXPR_P (DECL_TI_TEMPLATE (fun)))
+ || (DECL_DEFAULTED_FN (fun)
+ && DECL_DECLARED_CONSTEXPR_P (fun)));
+
}
/* Generate RTL for FN. */
if (is_valid_constexpr_fn (fun, true))
{
/* Then if it's OK, the body. */
- if (DECL_DEFAULTED_FN (fun))
+ if (!DECL_DECLARED_CONSTEXPR_P (fun))
explain_implicit_non_constexpr (fun);
else
{
--- /dev/null
+// PR c++/58511
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+ constexpr A(int, int = i) {}
+ static const int i;
+};
+
+struct B : A
+{
+ using A::A; // { dg-error "A::i" }
+};
+
+constexpr B b(0); // { dg-error "B::B" }
{
A a1 = 1; // { dg-error "" }
A a2 { 2 };
- A a3 = { 3 }; // { dg-error "" }
+ A a3 = { 3 }; // { dg-error "explicit" }
};
constexpr B b; // { dg-error "B::B" }
-// { dg-message "a1. is invalid" "" { target *-*-* } 11 }
+// { dg-prune-output "uninitialized member" }