diff options
author | Joseph Myers <joseph@codesourcery.com> | 2009-05-04 21:24:22 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2009-05-04 21:24:22 +0100 |
commit | 88388a52299144bba77776ebc27e343995aa4f3c (patch) | |
tree | 68743d2b81c50cab3b9196589c419307e1b8b58f /gcc/c-decl.c | |
parent | 960c5c791a8cf2314f09eb925cf8b48af2c9d662 (diff) | |
download | gcc-88388a52299144bba77776ebc27e343995aa4f3c.zip gcc-88388a52299144bba77776ebc27e343995aa4f3c.tar.gz gcc-88388a52299144bba77776ebc27e343995aa4f3c.tar.bz2 |
c-common.c (handle_mode_attribute): Use %qE for identifiers in diagnostics.
* c-common.c (handle_mode_attribute): Use %qE for identifiers in
diagnostics.
* c-decl.c (check_bitfield_type_and_width): Make orig_name a tree
and pass value to identifier_to_locale.
(warn_variable_length_array): Make name a tree.
(grokdeclarator): Separate diagnostic texts for named and unnamed
declarators. Use %qE for named declarators.
* c-parser.c (c_lex_one_token): Use %qE for identifiers in
diagnostics.
* c-pragma.c (pop_alignment, handle_pragma_pack): Use %qE for
identifiers in diagnostics.
* c-typeck.c (push_member_name, start_init): Pass identifiers to
identifier_to_locale. Mark "anonymous" strings for translation.
testsuite:
* gcc.dg/ucnid-8.c, gcc.dg/ucnid-9.c, gcc.dg/ucnid-10.c: New
tests.
* gcc.dg/declspec-9.c, gcc.dg/declspec-10.c, gcc.dg/declspec-11.c:
Update expected errors.
From-SVN: r147108
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 152 |
1 files changed, 105 insertions, 47 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 88bfa25..a851c6d 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -3894,12 +3894,14 @@ flexible_array_type_p (tree type) /* 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. */ @@ -3967,7 +3969,7 @@ check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name) /* 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); @@ -3976,7 +3978,8 @@ warn_variable_length_array (const char *name, tree 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 @@ -3986,7 +3989,8 @@ warn_variable_length_array (const char *name, tree size) 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"); @@ -3998,7 +4002,7 @@ warn_variable_length_array (const char *name, tree size) { 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, @@ -4008,7 +4012,7 @@ warn_variable_length_array (const char *name, tree size) { if (name) warning (OPT_Wvla, - "variable length array %qs is used", + "variable length array %qE is used", name); else warning (OPT_Wvla, @@ -4098,7 +4102,7 @@ grokdeclarator (const struct c_declarator *declarator, 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; @@ -4126,10 +4130,9 @@ grokdeclarator (const struct c_declarator *declarator, 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) @@ -4147,16 +4150,21 @@ grokdeclarator (const struct c_declarator *declarator, 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 @@ -4178,7 +4186,10 @@ grokdeclarator (const struct c_declarator *declarator, && 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; } @@ -4194,9 +4205,16 @@ grokdeclarator (const struct c_declarator *declarator, 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, @@ -4270,11 +4288,17 @@ grokdeclarator (const struct c_declarator *declarator, 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"); @@ -4294,26 +4318,26 @@ grokdeclarator (const struct c_declarator *declarator, /* 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; @@ -4407,13 +4431,19 @@ grokdeclarator (const struct c_declarator *declarator, 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; } @@ -4444,22 +4474,34 @@ grokdeclarator (const struct c_declarator *declarator, 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 @@ -4474,16 +4516,17 @@ grokdeclarator (const struct c_declarator *declarator, 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 @@ -4492,7 +4535,7 @@ grokdeclarator (const struct c_declarator *declarator, 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) @@ -4533,7 +4576,10 @@ grokdeclarator (const struct c_declarator *declarator, 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; } @@ -4686,12 +4732,20 @@ grokdeclarator (const struct c_declarator *declarator, /* 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; } @@ -4806,7 +4860,7 @@ grokdeclarator (const struct c_declarator *declarator, /* 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? */ @@ -4815,7 +4869,10 @@ grokdeclarator (const struct c_declarator *declarator, && 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; @@ -4880,7 +4937,7 @@ grokdeclarator (const struct c_declarator *declarator, && !(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; } @@ -4958,13 +5015,13 @@ grokdeclarator (const struct c_declarator *declarator, 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); @@ -4981,7 +5038,7 @@ grokdeclarator (const struct c_declarator *declarator, { 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) { @@ -4991,10 +5048,11 @@ grokdeclarator (const struct c_declarator *declarator, 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 |