Commit a90caaa2 by Jason Merrill Committed by Jason Merrill

re PR c++/48296 ([C++0x] constexpr member function cannot use the class type it…

re PR c++/48296 ([C++0x] constexpr member function cannot use the class type it belongs as parameter type or return type)

	PR c++/48296
	* decl.c (cp_finish_decl): Defer validation of constexpr member
	functions.
	* class.c (finalize_literal_type_property): Validate them here.
	* semantics.c (is_valid_constexpr_fn): Don't check completeness.

From-SVN: r171661
parent 915829cc
2011-03-29 Jason Merrill <jason@redhat.com> 2011-03-29 Jason Merrill <jason@redhat.com>
PR c++/48296
* decl.c (cp_finish_decl): Defer validation of constexpr member
functions.
* class.c (finalize_literal_type_property): Validate them here.
* semantics.c (is_valid_constexpr_fn): Don't check completeness.
* semantics.c (is_valid_constexpr_fn): Specify input location. * semantics.c (is_valid_constexpr_fn): Specify input location.
2011-03-28 Jason Merrill <jason@redhat.com> 2011-03-28 Jason Merrill <jason@redhat.com>
......
...@@ -4549,6 +4549,8 @@ type_requires_array_cookie (tree type) ...@@ -4549,6 +4549,8 @@ type_requires_array_cookie (tree type)
static void static void
finalize_literal_type_property (tree t) finalize_literal_type_property (tree t)
{ {
tree fn;
if (cxx_dialect < cxx0x if (cxx_dialect < cxx0x
|| TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
/* FIXME These constraints seem unnecessary; remove from standard. /* FIXME These constraints seem unnecessary; remove from standard.
...@@ -4559,18 +4561,10 @@ finalize_literal_type_property (tree t) ...@@ -4559,18 +4561,10 @@ finalize_literal_type_property (tree t)
&& !TYPE_HAS_CONSTEXPR_CTOR (t)) && !TYPE_HAS_CONSTEXPR_CTOR (t))
CLASSTYPE_LITERAL_P (t) = false; CLASSTYPE_LITERAL_P (t) = false;
if (!CLASSTYPE_LITERAL_P (t) && !CLASSTYPE_TEMPLATE_INSTANTIATION (t))
{
tree fn;
for (fn = TYPE_METHODS (t); fn; fn = DECL_CHAIN (fn)) for (fn = TYPE_METHODS (t); fn; fn = DECL_CHAIN (fn))
if (DECL_DECLARED_CONSTEXPR_P (fn) if (DECL_DECLARED_CONSTEXPR_P (fn)
&& DECL_NONSTATIC_MEMBER_FUNCTION_P (fn) && TREE_CODE (fn) != TEMPLATE_DECL)
&& !DECL_CONSTRUCTOR_P (fn)) validate_constexpr_fundecl (fn);
{
error ("enclosing class of %q+D is not a literal type", fn);
DECL_DECLARED_CONSTEXPR_P (fn) = false;
}
}
} }
/* Check the validity of the bases and members declared in T. Add any /* Check the validity of the bases and members declared in T. Add any
......
...@@ -5794,7 +5794,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, ...@@ -5794,7 +5794,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
} }
} }
if (TREE_CODE (decl) == FUNCTION_DECL) if (TREE_CODE (decl) == FUNCTION_DECL
/* For members, defer until finalize_literal_type_property. */
&& (!DECL_CLASS_SCOPE_P (decl)
|| !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))))
validate_constexpr_fundecl (decl); validate_constexpr_fundecl (decl);
else if (!ensure_literal_type_for_constexpr_object (decl)) else if (!ensure_literal_type_for_constexpr_object (decl))
......
...@@ -5354,8 +5354,7 @@ is_valid_constexpr_fn (tree fun, bool complain) ...@@ -5354,8 +5354,7 @@ is_valid_constexpr_fn (tree fun, bool complain)
} }
if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun) if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun)
&& COMPLETE_TYPE_P (DECL_CONTEXT (fun)) && !CLASSTYPE_LITERAL_P (DECL_CONTEXT (fun)))
&& !valid_type_in_constexpr_fundecl_p (DECL_CONTEXT (fun)))
{ {
ret = false; ret = false;
if (complain) if (complain)
......
2011-03-29 Jason Merrill <jason@redhat.com> 2011-03-29 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/constexpr-memfn1.C: New.
* g++.dg/cpp0x/constexpr-diag1.C: Adjust error locations. * g++.dg/cpp0x/constexpr-diag1.C: Adjust error locations.
2011-03-29 Janus Weil <janus@gcc.gnu.org> 2011-03-29 Janus Weil <janus@gcc.gnu.org>
......
// PR c++/48296
// { dg-options -std=c++0x }
struct X
{
constexpr X() { }
constexpr X f(X x) { return x; }
constexpr X g(X x);
};
constexpr X X::g(X x) { return x; }
struct Y
{
Y() { }
constexpr Y f(Y y); // { dg-error "constexpr" }
static constexpr Y g(Y y); // { dg-error "constexpr" }
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment