static void
process_subob_fn (tree fn, bool move_p, tree *spec_p, bool *trivial_p,
- bool *deleted_p, const char *msg, tree arg)
+ bool *deleted_p, bool *constexpr_p,
+ const char *msg, tree arg)
{
if (!fn || fn == error_mark_node)
goto bad;
goto bad;
}
+ if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
+ *constexpr_p = false;
+
return;
bad:
walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
int quals, bool copy_arg_p, bool move_p,
bool assign_p, tree *spec_p, bool *trivial_p,
- bool *deleted_p, const char *msg,
+ bool *deleted_p, bool *constexpr_p, const char *msg,
int flags, tsubst_flags_t complain)
{
tree field;
if (bad && deleted_p)
*deleted_p = true;
+
+ /* For an implicitly-defined default constructor to be constexpr,
+ every member must have a user-provided default constructor. */
+ /* FIXME will need adjustment for non-static data member
+ initializers. */
+ if (constexpr_p && !CLASS_TYPE_P (mem_type))
+ *constexpr_p = false;
}
if (!CLASS_TYPE_P (mem_type))
{
walk_field_subobs (TYPE_FIELDS (mem_type), fnname, sfk, quals,
copy_arg_p, move_p, assign_p, spec_p, trivial_p,
- deleted_p, msg, flags, complain);
+ deleted_p, constexpr_p, msg, flags, complain);
continue;
}
rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
- msg, field);
+ constexpr_p, msg, field);
}
}
static void
synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
tree *spec_p, bool *trivial_p, bool *deleted_p,
- bool diag)
+ bool *constexpr_p, bool diag)
{
tree binfo, base_binfo, scope, fnname, rval, argtype;
bool move_p, copy_arg_p, assign_p, expected_trivial, check_vdtor;
*deleted_p = false;
}
+ ctor_p = false;
+ assign_p = false;
+ check_vdtor = false;
+ switch (sfk)
+ {
+ case sfk_move_assignment:
+ case sfk_copy_assignment:
+ assign_p = true;
+ fnname = ansi_assopname (NOP_EXPR);
+ break;
+
+ case sfk_destructor:
+ check_vdtor = true;
+ /* The synthesized method will call base dtors, but check complete
+ here to avoid having to deal with VTT. */
+ fnname = complete_dtor_identifier;
+ break;
+
+ case sfk_constructor:
+ case sfk_move_constructor:
+ case sfk_copy_constructor:
+ ctor_p = true;
+ fnname = complete_ctor_identifier;
+ break;
+
+ default:
+ gcc_unreachable ();
+ }
+
+ /* If that user-written default constructor would satisfy the
+ requirements of a constexpr constructor (7.1.5), the
+ implicitly-defined default constructor is constexpr. */
+ if (constexpr_p)
+ *constexpr_p = ctor_p;
+
move_p = false;
switch (sfk)
{
return;
#endif
- ctor_p = false;
- assign_p = false;
- check_vdtor = false;
- switch (sfk)
- {
- case sfk_move_assignment:
- case sfk_copy_assignment:
- assign_p = true;
- fnname = ansi_assopname (NOP_EXPR);
- break;
-
- case sfk_destructor:
- check_vdtor = true;
- /* The synthesized method will call base dtors, but check complete
- here to avoid having to deal with VTT. */
- fnname = complete_dtor_identifier;
- break;
-
- case sfk_constructor:
- case sfk_move_constructor:
- case sfk_copy_constructor:
- ctor_p = true;
- fnname = complete_ctor_identifier;
- break;
-
- default:
- gcc_unreachable ();
- }
-
++cp_unevaluated_operand;
++c_inhibit_evaluation_warnings;
rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
- msg, basetype);
+ constexpr_p, msg, basetype);
if (ctor_p && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype))
{
/* In a constructor we also need to check the subobject
rval = locate_fn_flags (base_binfo, complete_dtor_identifier,
NULL_TREE, flags, complain);
process_subob_fn (rval, false, &cleanup_spec, &cleanup_trivial,
- &cleanup_deleted, NULL, basetype);
+ &cleanup_deleted, NULL, NULL,
+ basetype);
}
if (check_vdtor && type_has_virtual_destructor (basetype))
if (diag)
msg = ("virtual base %qT does not have a move constructor "
"or trivial copy constructor");
+ if (vbases && constexpr_p)
+ *constexpr_p = false;
FOR_EACH_VEC_ELT (tree, vbases, i, base_binfo)
{
tree basetype = BINFO_TYPE (base_binfo);
rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
- msg, basetype);
+ constexpr_p, msg, basetype);
if (ctor_p && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype))
{
rval = locate_fn_flags (base_binfo, complete_dtor_identifier,
NULL_TREE, flags, complain);
process_subob_fn (rval, false, &cleanup_spec, &cleanup_trivial,
- &cleanup_deleted, NULL, basetype);
+ &cleanup_deleted, NULL, NULL,
+ basetype);
}
}
}
"constructor or trivial copy constructor");
walk_field_subobs (TYPE_FIELDS (ctype), fnname, sfk, quals,
copy_arg_p, move_p, assign_p, spec_p, trivial_p,
- deleted_p, msg, flags, complain);
+ deleted_p, constexpr_p, msg, flags, complain);
if (ctor_p)
walk_field_subobs (TYPE_FIELDS (ctype), complete_dtor_identifier,
sfk_destructor, TYPE_UNQUALIFIED, false,
false, false, &cleanup_spec, &cleanup_trivial,
- &cleanup_deleted, NULL, flags, complain);
+ &cleanup_deleted, NULL,
+ NULL, flags, complain);
pop_scope (scope);
"definition would be ill-formed:", decl);
pop_scope (scope);
synthesized_method_walk (ctype, sfk, const_p,
- NULL, NULL, NULL, true);
+ NULL, NULL, NULL, NULL, true);
}
input_location = loc;
HOST_WIDE_INT saved_processing_template_decl;
bool deleted_p;
bool trivial_p;
+ bool constexpr_p;
/* Because we create declarations for implicitly declared functions
lazily, we may be creating the declaration for a member of TYPE
}
synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
- &deleted_p, false);
+ &deleted_p, &constexpr_p, false);
+ /* Don't bother marking a deleted constructor as constexpr. */
+ if (deleted_p)
+ constexpr_p = false;
+ /* A trivial copy/move constructor is also a constexpr constructor. */
+ else if (trivial_p && cxx_dialect >= cxx0x
+ && (kind == sfk_copy_constructor
+ || kind == sfk_move_constructor))
+ gcc_assert (constexpr_p);
if (!trivial_p && type_has_trivial_fn (type, kind))
type_set_nontrivial_flag (type, kind);
DECL_ARTIFICIAL (fn) = 1;
DECL_DEFAULTED_FN (fn) = 1;
if (cxx_dialect >= cxx0x)
- DECL_DELETED_FN (fn) = deleted_p;
+ {
+ DECL_DELETED_FN (fn) = deleted_p;
+ DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
+ }
DECL_NOT_REALLY_EXTERN (fn) = 1;
DECL_DECLARED_INLINE_P (fn) = 1;
gcc_assert (!TREE_USED (fn));
{
tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (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 (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
+ && DECL_DECLARED_CONSTEXPR_P (fn))
+ {
+ if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
+ error ("%qD cannot be declared as constexpr", fn);
+ DECL_DECLARED_CONSTEXPR_P (fn) = false;
}
if (DECL_DELETED_FN (implicit_fn))