static int template_parm_this_level_p PARAMS ((tree, void *));
static tree tsubst_friend_function PARAMS ((tree, tree));
static tree tsubst_friend_class PARAMS ((tree, tree));
+static int can_complete_type_without_circularity PARAMS ((tree));
static tree get_bindings_real PARAMS ((tree, tree, tree, int, int, int));
static int template_decl_level PARAMS ((tree));
static tree maybe_get_template_decl_from_type_decl PARAMS ((tree));
return friend_type;
}
+/* Returns zero if TYPE cannot be completed later due to circularity.
+ Otherwise returns one. */
+
+int
+can_complete_type_without_circularity (type)
+ tree type;
+{
+ if (type == NULL_TREE || type == error_mark_node)
+ return 0;
+ else if (COMPLETE_TYPE_P (type))
+ return 1;
+ else if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type))
+ return can_complete_type_without_circularity (TREE_TYPE (type));
+ else if (CLASS_TYPE_P (type) && TYPE_BEING_DEFINED (TYPE_MAIN_VARIANT (type)))
+ return 0;
+ else
+ return 1;
+}
+
tree
instantiate_class_template (type)
tree type;
if (DECL_INITIALIZED_IN_CLASS_P (r))
check_static_variable_definition (r, TREE_TYPE (r));
}
-
+ else if (TREE_CODE (r) == FIELD_DECL)
+ {
+ /* Determine whether R has a valid type and can be
+ completed later. If R is invalid, then it is replaced
+ by error_mark_node so that it will not be added to
+ TYPE_FIELDS. */
+ tree rtype = TREE_TYPE (r);
+ if (!can_complete_type_without_circularity (rtype))
+ {
+ incomplete_type_error (r, rtype);
+ r = error_mark_node;
+ }
+ }
+
/* R will have a TREE_CHAIN if and only if it has already been
processed by finish_member_declaration. This can happen
if, for example, it is a TYPE_DECL for a class-scoped
--processing_template_decl;
}
+ /* Now that TYPE_FIELDS and TYPE_METHODS are set up. We can
+ instantiate templates used by this class. */
for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
if (TREE_CODE (t) == FIELD_DECL)
{
return;
if (value != 0 && (TREE_CODE (value) == VAR_DECL
- || TREE_CODE (value) == PARM_DECL))
+ || TREE_CODE (value) == PARM_DECL
+ || TREE_CODE (value) == FIELD_DECL))
{
(*p_msg_at) ("`%D' has incomplete type", value);
decl = 1;
case ENUMERAL_TYPE:
if (!decl)
(*p_msg) ("invalid use of undefined type `%#T'", type);
- (*p_msg_at) ("forward declaration of `%#T'", type);
+ if (!TYPE_TEMPLATE_INFO (type))
+ (*p_msg_at) ("forward declaration of `%#T'", type);
+ else
+ (*p_msg_at) ("forward declaration of `%#T'", type);
break;
case VOID_TYPE: