2011-09-04 Jason Merrill <jason@redhat.com>
+ * class.c (trivial_default_constructor_is_constexpr): Rename from
+ synthesized_default_constructor_is_constexpr.
+ (type_has_constexpr_default_constructor): Adjust.
+ (add_implicitly_declared_members): Call it instead.
+ (explain_non_literal_class): Explain about non-constexpr default ctor.
+ * cp-tree.h: Adjust.
+ * method.c (synthesized_method_walk): Adjust.
+ * semantics.c (explain_invalid_constexpr_fn): Handle defaulted
+ functions, too.
+
PR c++/50248
Core 1358
* init.c (perform_member_init): Don't diagnose missing inits here.
CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
if (cxx_dialect >= cxx0x)
TYPE_HAS_CONSTEXPR_CTOR (t)
- = synthesized_default_constructor_is_constexpr (t);
+ /* This might force the declaration. */
+ = type_has_constexpr_default_constructor (t);
}
/* [class.ctor]
return false;
}
-/* Returns true iff for class T, a synthesized default constructor
+/* Returns true iff for class T, a trivial synthesized default constructor
would be constexpr. */
bool
-synthesized_default_constructor_is_constexpr (tree t)
+trivial_default_constructor_is_constexpr (tree t)
{
- /* A defaulted default constructor is constexpr
+ /* A defaulted trivial default constructor is constexpr
if there is nothing to initialize. */
- /* FIXME adjust for non-static data member initializers. */
+ gcc_assert (!TYPE_HAS_COMPLEX_DFLT (t));
return is_really_empty_class (t);
}
return false;
}
if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
- return synthesized_default_constructor_is_constexpr (t);
+ {
+ if (!TYPE_HAS_COMPLEX_DFLT (t))
+ return trivial_default_constructor_is_constexpr (t);
+ /* Non-trivial, we need to check subobject constructors. */
+ lazily_declare_fn (sfk_constructor, t);
+ }
fns = locate_ctor (t);
return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
}
else if (CLASSTYPE_NON_AGGREGATE (t)
&& !TYPE_HAS_TRIVIAL_DFLT (t)
&& !TYPE_HAS_CONSTEXPR_CTOR (t))
- inform (0, " %q+T is not an aggregate, does not have a trivial "
- "default constructor, and has no constexpr constructor that "
- "is not a copy or move constructor", t);
+ {
+ inform (0, " %q+T is not an aggregate, does not have a trivial "
+ "default constructor, and has no constexpr constructor that "
+ "is not a copy or move constructor", t);
+ if (TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
+ && !type_has_user_provided_default_constructor (t))
+ explain_invalid_constexpr_fn (locate_ctor (t));
+ }
else
{
tree binfo, base_binfo, field; int i;
extern bool user_provided_p (tree);
extern bool type_has_user_provided_constructor (tree);
extern bool type_has_user_provided_default_constructor (tree);
-extern bool synthesized_default_constructor_is_constexpr (tree);
+extern bool trivial_default_constructor_is_constexpr (tree);
extern bool type_has_constexpr_default_constructor (tree);
extern bool type_has_virtual_destructor (tree);
extern bool type_has_move_constructor (tree);