diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-06-29 14:34:58 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-06-29 14:34:58 +0000 |
commit | 262c8920a693a1b1d705547abccd1cc826dd6d1f (patch) | |
tree | c78bb4975e01ac82dfc07cfc5592be17dedd13d2 /gcc/cp/method.c | |
parent | 68224783dd6d27b0d911e1f1cc4f3639e354d051 (diff) | |
download | gcc-262c8920a693a1b1d705547abccd1cc826dd6d1f.tar.gz |
PR c++/45923
* class.c (explain_non_literal_class): New.
(finalize_literal_type_property): Call it.
* cp-tree.h: Declare it.
* semantics.c (ensure_literal_type_for_constexpr_object): Call it.
(is_valid_constexpr_fn): Likewise.
(massage_constexpr_body): Split out from...
(register_constexpr_fundef): ...here.
(is_instantiation_of_constexpr): New.
(expand_or_defer_fn_1): Leave DECL_SAVED_TREE alone in that case.
(explain_invalid_constexpr_fn): New.
(cxx_eval_call_expression): Call it.
(potential_constant_expression_1): Likewise. Avoid redundant errors.
* method.c (process_subob_fn): Diagnose non-constexpr.
(walk_field_subobs): Likewise.
(synthesized_method_walk): Don't shortcut if we want diagnostics.
(explain_implicit_non_constexpr): New.
(defaulted_late_check): Use it.
* call.c (build_cxx_call): Remember location.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@175646 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/method.c')
-rw-r--r-- | gcc/cp/method.c | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/gcc/cp/method.c b/gcc/cp/method.c index ec1c5025278..f10e846d0ea 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -958,7 +958,15 @@ process_subob_fn (tree fn, bool move_p, tree *spec_p, bool *trivial_p, && !DECL_TEMPLATE_INSTANTIATED (fn)) instantiate_decl (fn, /*defer_ok*/false, /*expl_class*/false); if (!DECL_DECLARED_CONSTEXPR_P (fn)) - *constexpr_p = false; + { + *constexpr_p = false; + if (msg) + { + inform (0, "defaulted constructor calls non-constexpr " + "%q+D", fn); + explain_invalid_constexpr_fn (fn); + } + } } return; @@ -1037,7 +1045,12 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk, /* FIXME will need adjustment for non-static data member initializers. */ if (constexpr_p && !CLASS_TYPE_P (mem_type)) - *constexpr_p = false; + { + *constexpr_p = false; + if (msg) + inform (0, "defaulted default constructor does not " + "initialize %q+#D", field); + } } if (!CLASS_TYPE_P (mem_type)) @@ -1071,8 +1084,9 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk, /* The caller wants to generate an implicit declaration of SFK for CTYPE which is const if relevant and CONST_P is set. If spec_p, trivial_p and deleted_p are non-null, set their referent appropriately. If diag is - true, we're being called from maybe_explain_implicit_delete to give - errors. */ + true, we're either being called from maybe_explain_implicit_delete to + give errors, or if constexpr_p is non-null, from + explain_invalid_constexpr_fn. */ static void synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p, @@ -1175,6 +1189,7 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p, resolution, so a constructor can be trivial even if it would otherwise call a non-trivial constructor. */ if (expected_trivial + && !diag && (!copy_arg_p || cxx_dialect < cxx0x)) { if (constexpr_p && sfk == sfk_constructor) @@ -1366,6 +1381,20 @@ maybe_explain_implicit_delete (tree decl) return false; } +/* DECL is a defaulted function which was declared constexpr. Explain why + it can't be constexpr. */ + +void +explain_implicit_non_constexpr (tree decl) +{ + tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl)); + bool const_p = CP_TYPE_CONST_P (non_reference (parm_type)); + bool dummy; + synthesized_method_walk (DECL_CLASS_CONTEXT (decl), + special_function_p (decl), const_p, + NULL, NULL, NULL, &dummy, true); +} + /* Implicitly declare the special function indicated by KIND, as a member of TYPE. For copy constructors and assignment operators, CONST_P indicates whether these functions should take a const @@ -1581,7 +1610,12 @@ defaulted_late_check (tree fn) && DECL_DECLARED_CONSTEXPR_P (fn)) { if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx)) - error ("%qD cannot be declared as constexpr", fn); + { + error ("explicitly defaulted function %q+D cannot be declared " + "as constexpr because the implicit declaration is not " + "constexpr:", fn); + explain_implicit_non_constexpr (fn); + } DECL_DECLARED_CONSTEXPR_P (fn) = false; } |