+2004-10-09 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/17524
+ * cp-tree.h (check_var_type): New function.
+ * decl.c (check_var_type): New function, split out from ...
+ (grokdeclarator): ... here.
+ * pt.c (tsubst_decl): Use check_var_type.
+
+ PR c++/17685
+ * decl.c (grokdeclarator): Disallow declarations of operators as
+ non-functions.
+
2004-10-08 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/17868
return type;
}
+/* A variable or data member (whose unqualified name is IDENTIFIER)
+ has been declared with the indicated TYPE. If the TYPE is not
+ acceptable, issue an error message and return a type to use for
+ error-recovery purposes. */
+
+tree
+check_var_type (tree identifier, tree type)
+{
+ if (VOID_TYPE_P (type))
+ {
+ if (!identifier)
+ error ("unnamed variable or field declared void");
+ else if (TREE_CODE (identifier) == IDENTIFIER_NODE)
+ {
+ gcc_assert (!IDENTIFIER_OPNAME_P (identifier));
+ error ("variable or field %qE declared void", identifier);
+ }
+ else
+ error ("variable or field declared void");
+ type = integer_type_node;
+ }
+
+ return type;
+}
+
/* Given declspecs and a declarator (abstract or otherwise), determine
the name and type of the object declared and construct a DECL node
for it.
unqualified_id = make_anon_name ();
}
- /* `void' at top level (not within pointer)
- is allowed only in typedefs or type names.
- We don't complain about parms either, but that is because
- a better error message can be made later. */
-
- if (TREE_CODE (type) == VOID_TYPE && decl_context != PARM)
+ /* Only functions may be declared using an operator-function-id. */
+ if (unqualified_id
+ && IDENTIFIER_OPNAME_P (unqualified_id)
+ && TREE_CODE (type) != FUNCTION_TYPE
+ && TREE_CODE (type) != METHOD_TYPE)
{
- if (! unqualified_id)
- error ("unnamed variable or field declared void");
- else if (TREE_CODE (unqualified_id) == IDENTIFIER_NODE)
- {
- gcc_assert (!IDENTIFIER_OPNAME_P (unqualified_id));
- error ("variable or field %qs declared void", name);
- }
- else
- error ("variable or field declared void");
- type = integer_type_node;
+ error ("declaration of %qD as non-function", unqualified_id);
+ return error_mark_node;
}
+ /* We don't check parameter types here because we can emit a better
+ error message later. */
+ if (decl_context != PARM)
+ type = check_var_type (unqualified_id, type);
+
/* Now create the decl, which may be a VAR_DECL, a PARM_DECL
or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
type = complete_type (type);
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (r)
= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (t);
+ type = check_var_type (DECL_NAME (r), type);
}
else if (DECL_SELF_REFERENCE_P (t))
SET_DECL_SELF_REFERENCE_P (r);
register_local_specialization (r, t);
TREE_CHAIN (r) = NULL_TREE;
- if (TREE_CODE (r) == VAR_DECL && VOID_TYPE_P (type))
- cp_error_at ("instantiation of %qD as type %qT", r, type);
- /* Compute the size, alignment, etc. of R. */
layout_decl (r, 0);
}
break;