/* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
replacing with appropriate values if they are invalid. */
static void
-check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name)
+check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
{
tree type_mv;
unsigned int max_width;
unsigned HOST_WIDE_INT w;
- const char *name = orig_name ? orig_name: _("<anonymous>");
+ const char *name = (orig_name
+ ? identifier_to_locale (IDENTIFIER_POINTER (orig_name))
+ : _("<anonymous>"));
/* Detect and ignore out of range field width and process valid
field widths. */
/* Print warning about variable length array if necessary. */
static void
-warn_variable_length_array (const char *name, tree size)
+warn_variable_length_array (tree name, tree size)
{
int const_size = TREE_CONSTANT (size);
if (const_size)
{
if (name)
- pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array %qs whose size "
+ pedwarn (input_location, OPT_Wvla,
+ "ISO C90 forbids array %qE whose size "
"can%'t be evaluated",
name);
else
else
{
if (name)
- pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array %qs",
+ pedwarn (input_location, OPT_Wvla,
+ "ISO C90 forbids variable length array %qE",
name);
else
pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array");
{
if (name)
warning (OPT_Wvla,
- "the size of array %qs can"
+ "the size of array %qE can"
"%'t be evaluated", name);
else
warning (OPT_Wvla,
{
if (name)
warning (OPT_Wvla,
- "variable length array %qs is used",
+ "variable length array %qE is used",
name);
else
warning (OPT_Wvla,
int restrictp;
int volatilep;
int type_quals = TYPE_UNQUALIFIED;
- const char *name, *orig_name;
+ tree name = NULL_TREE;
bool funcdef_flag = false;
bool funcdef_syntax = false;
int size_varies = 0;
funcdef_flag = true, decl_context = NORMAL;
/* Look inside a declarator for the name being declared
- and get it as a string, for an error message. */
+ and get it as an IDENTIFIER_NODE, for an error message. */
{
const struct c_declarator *decl = declarator;
- name = 0;
while (decl)
switch (decl->kind)
case cdk_id:
if (decl->u.id)
- name = IDENTIFIER_POINTER (decl->u.id);
+ name = decl->u.id;
decl = 0;
break;
default:
gcc_unreachable ();
}
- orig_name = name;
if (name == 0)
- name = "type name";
+ {
+ gcc_assert (decl_context == PARM
+ || decl_context == TYPENAME
+ || (decl_context == FIELD
+ && declarator->kind == cdk_id));
+ gcc_assert (!initialized);
+ }
}
/* A function definition's declarator must have the form of
&& current_scope == file_scope
&& variably_modified_type_p (type, NULL_TREE))
{
- error ("variably modified %qs at file scope", name);
+ if (name)
+ error ("variably modified %qE at file scope", name);
+ else
+ error ("variably modified field at file scope");
type = integer_type_node;
}
if ((warn_implicit_int || warn_return_type || flag_isoc99)
&& funcdef_flag)
warn_about_return_type = 1;
- else
- pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int,
- "type defaults to %<int%> in declaration of %qs", name);
+ else
+ {
+ if (name)
+ pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int,
+ "type defaults to %<int%> in declaration of %qE",
+ name);
+ else
+ pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int,
+ "type defaults to %<int%> in type name");
+ }
}
/* Adjust the type if a bit-field is being declared,
switch (decl_context)
{
case FIELD:
- error ("storage class specified for structure field %qs",
- name);
+ if (name)
+ error ("storage class specified for structure field %qE",
+ name);
+ else
+ error ("storage class specified for structure field");
break;
case PARM:
- error ("storage class specified for parameter %qs", name);
+ if (name)
+ error ("storage class specified for parameter %qE", name);
+ else
+ error ("storage class specified for unnamed parameter");
break;
default:
error ("storage class specified for typename");
/* It is fine to have 'extern const' when compiling at C
and C++ intersection. */
if (!(warn_cxx_compat && constp))
- warning (0, "%qs initialized and declared %<extern%>", name);
+ warning (0, "%qE initialized and declared %<extern%>", name);
}
else
- error ("%qs has both %<extern%> and initializer", name);
+ error ("%qE has both %<extern%> and initializer", name);
}
else if (current_scope == file_scope)
{
if (storage_class == csc_auto)
- error ("file-scope declaration of %qs specifies %<auto%>", name);
+ error ("file-scope declaration of %qE specifies %<auto%>", name);
if (pedantic && storage_class == csc_register)
pedwarn (input_location, OPT_pedantic,
- "file-scope declaration of %qs specifies %<register%>", name);
+ "file-scope declaration of %qE specifies %<register%>", name);
}
else
{
if (storage_class == csc_extern && funcdef_flag)
- error ("nested function %qs declared %<extern%>", name);
+ error ("nested function %qE declared %<extern%>", name);
else if (threadp && storage_class == csc_none)
{
- error ("function-scope %qs implicitly auto and declared "
+ error ("function-scope %qE implicitly auto and declared "
"%<__thread%>",
name);
threadp = false;
if (VOID_TYPE_P (type))
{
- error ("declaration of %qs as array of voids", name);
+ if (name)
+ error ("declaration of %qE as array of voids", name);
+ else
+ error ("declaration of type name as array of voids");
type = error_mark_node;
}
if (TREE_CODE (type) == FUNCTION_TYPE)
{
- error ("declaration of %qs as array of functions", name);
+ if (name)
+ error ("declaration of %qE as array of functions", name);
+ else
+ error ("declaration of type name as array of functions");
type = error_mark_node;
}
if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
{
- error ("size of array %qs has non-integer type", name);
+ if (name)
+ error ("size of array %qE has non-integer type", name);
+ else
+ error ("size of unnamed array has non-integer type");
size = integer_one_node;
}
size = c_fully_fold (size, false, &size_maybe_const);
if (pedantic && size_maybe_const && integer_zerop (size))
- pedwarn (input_location, OPT_pedantic,
- "ISO C forbids zero-size array %qs", name);
+ {
+ if (name)
+ pedwarn (input_location, OPT_pedantic,
+ "ISO C forbids zero-size array %qE", name);
+ else
+ pedwarn (input_location, OPT_pedantic,
+ "ISO C forbids zero-size array");
+ }
if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
{
constant_expression_warning (size);
if (tree_int_cst_sgn (size) < 0)
{
- error ("size of array %qs is negative", name);
+ if (name)
+ error ("size of array %qE is negative", name);
+ else
+ error ("size of unnamed array is negative");
size = integer_one_node;
}
/* Handle a size folded to an integer constant but
if ((decl_context == NORMAL || decl_context == FIELD)
&& current_scope == file_scope)
pedwarn (input_location, 0,
- "variably modified %qs at file scope", name);
+ "variably modified %qE at file scope",
+ name);
else
this_size_varies = size_varies = 1;
- warn_variable_length_array (orig_name, size);
+ warn_variable_length_array (name, size);
}
}
else if ((decl_context == NORMAL || decl_context == FIELD)
&& current_scope == file_scope)
{
- error ("variably modified %qs at file scope", name);
+ error ("variably modified %qE at file scope", name);
size = integer_one_node;
}
else
nonconstant even if it is (eg) a const variable
with known value. */
this_size_varies = size_varies = 1;
- warn_variable_length_array (orig_name, size);
+ warn_variable_length_array (name, size);
}
if (integer_zerop (size) && !this_size_varies)
if (TREE_CODE (itype) == INTEGER_CST
&& TREE_OVERFLOW (itype))
{
- error ("size of array %qs is too large", name);
+ if (name)
+ error ("size of array %qE is too large", name);
+ else
+ error ("size of unnamed array is too large");
type = error_mark_node;
continue;
}
/* Warn about some types functions can't return. */
if (TREE_CODE (type) == FUNCTION_TYPE)
{
- error ("%qs declared as function returning a function", name);
+ if (name)
+ error ("%qE declared as function returning a function",
+ name);
+ else
+ error ("type name declared as function "
+ "returning a function");
type = integer_type_node;
}
if (TREE_CODE (type) == ARRAY_TYPE)
{
- error ("%qs declared as function returning an array", name);
+ if (name)
+ error ("%qE declared as function returning an array", name);
+ else
+ error ("type name declared as function returning an array");
type = integer_type_node;
}
/* Check the type and width of a bit-field. */
if (bitfield)
- check_bitfield_type_and_width (&type, width, orig_name);
+ check_bitfield_type_and_width (&type, width, name);
/* Did array size calculations overflow? */
&& TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
&& TREE_OVERFLOW (TYPE_SIZE_UNIT (type)))
{
- error ("size of array %qs is too large", name);
+ if (name)
+ error ("size of array %qE is too large", name);
+ else
+ error ("size of unnamed array is too large");
/* If we proceed with the array type as it is, we'll eventually
crash in tree_low_cst(). */
type = error_mark_node;
&& !(storage_class == csc_static
|| storage_class == csc_register)))))
{
- error ("variable or field %qs declared void", name);
+ error ("variable or field %qE declared void", name);
type = integer_type_node;
}
if (TREE_CODE (type) == FUNCTION_TYPE)
{
- error ("field %qs declared as a function", name);
+ error ("field %qE declared as a function", name);
type = build_pointer_type (type);
}
else if (TREE_CODE (type) != ERROR_MARK
&& !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
{
- error ("field %qs has incomplete type", name);
+ error ("field %qE has incomplete type", name);
type = error_mark_node;
}
type = c_build_qualified_type (type, type_quals);
{
if (storage_class == csc_register || threadp)
{
- error ("invalid storage class for function %qs", name);
+ error ("invalid storage class for function %qE", name);
}
else if (current_scope != file_scope)
{
GCC allows 'auto', perhaps with 'inline', to support
nested functions. */
if (storage_class == csc_auto)
- pedwarn (input_location, OPT_pedantic, "invalid storage class for function %qs", name);
+ pedwarn (input_location, OPT_pedantic,
+ "invalid storage class for function %qE", name);
else if (storage_class == csc_static)
{
- error ("invalid storage class for function %qs", name);
+ error ("invalid storage class for function %qE", name);
if (funcdef_flag)
storage_class = declspecs->storage_class = csc_none;
else