On 05/11/2011 05:27 PM, Jason Merrill wrote:
We want to allow a constexpr friend function that takes the current
class, so we need to defer checking the literality of parameter types
until any classes involved are complete.
It was pointed out to me that the restriction already only applies to
function definitions, not declarations, which dramatically simplifies
the code. This patch reverts most of the previous one, and only checks
return/parameter types at the point of definition.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit f2a2c7b6af06123b5f81bd474b60bddfe9b58550
Author: Jason Merrill ja...@redhat.com
Date: Mon May 16 17:21:17 2011 -0400
PR c++/48948
PR c++/49015
* class.c (finalize_literal_type_property): Do check
for constexpr member functions of non-literal class.
(finish_struct): Don't call check_deferred_constexpr_decls.
* cp-tree.h: Don't declare it.
(DECL_DEFERRED_CONSTEXPR_CHECK): Remove.
* decl.c (grok_special_member_properties): Don't check it
(grokfnedcl): Don't call validate_constexpr_fundecl.
(start_preparsed_function): Do call it.
* pt.c (tsubst_decl): Don't call it.
(instantiate_class_template_1): Don't call
check_deferred_constexpr_decls.
* semantics.c (literal_type_p): Check for any incompleteness.
(ensure_literal_type_for_constexpr_object): Likewise.
(is_valid_constexpr_fn): Revert deferral changes.
(validate_constexpr_fundecl): Likewise.
(register_constexpr_fundef): Likewise.
(check_deferred_constexpr_decls): Remove.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index dc2c509..4e52b18 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -4582,6 +4582,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.
@@ -4591,6 +4593,18 @@ finalize_literal_type_property (tree t)
else if (CLASSTYPE_LITERAL_P (t) !TYPE_HAS_TRIVIAL_DFLT (t)
!TYPE_HAS_CONSTEXPR_CTOR (t))
CLASSTYPE_LITERAL_P (t) = false;
+
+ if (!CLASSTYPE_LITERAL_P (t))
+for (fn = TYPE_METHODS (t); fn; fn = DECL_CHAIN (fn))
+ if (DECL_DECLARED_CONSTEXPR_P (fn)
+ TREE_CODE (fn) != TEMPLATE_DECL
+ DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
+ !DECL_CONSTRUCTOR_P (fn))
+ {
+ DECL_DECLARED_CONSTEXPR_P (fn) = false;
+ if (!DECL_TEMPLATE_INFO (fn))
+ error (enclosing class of %q+#D is not a literal type, fn);
+ }
}
/* Check the validity of the bases and members declared in T. Add any
@@ -5831,8 +5845,6 @@ finish_struct (tree t, tree attributes)
else
error (trying to finish struct, but kicked out due to previous parse errors);
- check_deferred_constexpr_decls ();
-
if (processing_template_decl at_function_scope_p ())
add_stmt (build_min (TAG_DEFN, t));
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index c0b5290..dfb2b66 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -93,7 +93,6 @@ c-common.h, not after.
TYPENAME_IS_RESOLVING_P (in TYPE_NAME_TYPE)
LAMBDA_EXPR_DEDUCE_RETURN_TYPE_P (in LAMBDA_EXPR)
TARGET_EXPR_DIRECT_INIT_P (in TARGET_EXPR)
- DECL_DEFERRED_CONSTEXPR_CHECK (in FUNCTION_DECL)
3: (TREE_REFERENCE_EXPR) (in NON_LVALUE_EXPR) (commented-out).
ICS_BAD_FLAG (in _CONV)
FN_TRY_BLOCK_P (in TRY_BLOCK)
@@ -2345,11 +2344,6 @@ struct GTY((variable_size)) lang_decl {
#define DECL_DECLARED_CONSTEXPR_P(DECL) \
DECL_LANG_FLAG_8 (VAR_OR_FUNCTION_DECL_CHECK (STRIP_TEMPLATE (DECL)))
-/* True if we can't tell yet whether the argument/return types of DECL
- are literal because one is still being defined. */
-#define DECL_DEFERRED_CONSTEXPR_CHECK(DECL) \
- TREE_LANG_FLAG_2 (FUNCTION_DECL_CHECK (STRIP_TEMPLATE (DECL)))
-
/* Nonzero if this DECL is the __PRETTY_FUNCTION__ variable in a
template function. */
#define DECL_PRETTY_FUNCTION_P(NODE) \
@@ -5337,7 +5331,6 @@ extern void finish_handler_parms (tree, tree);
extern void finish_handler (tree);
extern void finish_cleanup (tree, tree);
extern bool literal_type_p (tree);
-extern void check_deferred_constexpr_decls (void);
extern tree validate_constexpr_fundecl (tree);
extern tree register_constexpr_fundef (tree, tree);
extern bool check_constexpr_ctor_body (tree, tree);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7939140..e950c43 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7200,10 +7200,7 @@ grokfndecl (tree ctype,
if (inlinep)
DECL_DECLARED_INLINE_P (decl) = 1;
if (inlinep 2)
-{
- DECL_DECLARED_CONSTEXPR_P (decl) = true;
- validate_constexpr_fundecl (decl);
-}
+DECL_DECLARED_CONSTEXPR_P (decl) = true;
DECL_EXTERNAL (decl) = 1;
if (quals TREE_CODE (type) == FUNCTION_TYPE)
@@ -10681,9 +10678,6 @@ grok_special_member_properties (tree decl)
TYPE_HAS_LIST_CTOR (class_type) = 1;
if