aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2011-03-29 09:27:25 -0400
committerJason Merrill <jason@gcc.gnu.org>2011-03-29 09:27:25 -0400
commita90caaa2fde8b592910b232176e6f0f6188dcd0a (patch)
tree7b08622bab7763a062b742650b2f7d04fb7c3a28 /gcc
parent915829ccf1a380e5af8d7f59f53a9fe75bc778b1 (diff)
downloadgcc-a90caaa2fde8b592910b232176e6f0f6188dcd0a.zip
gcc-a90caaa2fde8b592910b232176e6f0f6188dcd0a.tar.gz
gcc-a90caaa2fde8b592910b232176e6f0f6188dcd0a.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/class.c18
-rw-r--r--gcc/cp/decl.c5
-rw-r--r--gcc/cp/semantics.c3
-rw-r--r--gcc/testsuite/ChangeLog2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-memfn1.C18
6 files changed, 37 insertions, 15 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 99a06d1..1ffe70b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
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.
2011-03-28 Jason Merrill <jason@redhat.com>
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index adae51f..24b8a31 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -4549,6 +4549,8 @@ type_requires_array_cookie (tree type)
static void
finalize_literal_type_property (tree t)
{
+ tree fn;
+
if (cxx_dialect < cxx0x
|| TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
/* FIXME These constraints seem unnecessary; remove from standard.
@@ -4559,18 +4561,10 @@ finalize_literal_type_property (tree t)
&& !TYPE_HAS_CONSTEXPR_CTOR (t))
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))
- if (DECL_DECLARED_CONSTEXPR_P (fn)
- && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
- && !DECL_CONSTRUCTOR_P (fn))
- {
- error ("enclosing class of %q+D is not a literal type", fn);
- DECL_DECLARED_CONSTEXPR_P (fn) = false;
- }
- }
+ for (fn = TYPE_METHODS (t); fn; fn = DECL_CHAIN (fn))
+ if (DECL_DECLARED_CONSTEXPR_P (fn)
+ && TREE_CODE (fn) != TEMPLATE_DECL)
+ validate_constexpr_fundecl (fn);
}
/* Check the validity of the bases and members declared in T. Add any
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 895527c..16ccfaf 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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);
else if (!ensure_literal_type_for_constexpr_object (decl))
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index da8c016..f1c3d9a 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5354,8 +5354,7 @@ is_valid_constexpr_fn (tree fun, bool complain)
}
if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun)
- && COMPLETE_TYPE_P (DECL_CONTEXT (fun))
- && !valid_type_in_constexpr_fundecl_p (DECL_CONTEXT (fun)))
+ && !CLASSTYPE_LITERAL_P (DECL_CONTEXT (fun)))
{
ret = false;
if (complain)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7214272..5cb4f4e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,7 @@
2011-03-29 Jason Merrill <jason@redhat.com>
+ * g++.dg/cpp0x/constexpr-memfn1.C: New.
+
* g++.dg/cpp0x/constexpr-diag1.C: Adjust error locations.
2011-03-29 Janus Weil <janus@gcc.gnu.org>
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-memfn1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-memfn1.C
new file mode 100644
index 0000000..4646f82
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-memfn1.C
@@ -0,0 +1,18 @@
+// 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" }
+};