From 6a8f4e12f5e44e292123c7424f703f8a7206e3a5 Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Tue, 8 Jun 2010 03:56:40 +0000 Subject: [PATCH] re PR c/37724 ("initialization from incompatible pointer type" does not say which field is being initialized) gcc/ 2010-06-08 Andrew Pinski Shujing Zhao PR c/37724 * c-typeck.c (convert_for_assignment): Call pedwarn_init if the implicit bad conversions is initialization. (error_init): Use gmsgid instead of msgid for argument name and change the call for error. (pedwarn_init): Use gmsgid instead of msgid for argument name and change the call for pedwarn. (warning_init): Use gmsgid instead of msgid for argument name and change the call for warning. gcc/testsuite/ 2010-06-08 Andrew Pinski Shujing Zhao PR c/37724 * gcc.dg/c90-const-expr-10.c: Adjust. * gcc.dg/c99-const-expr-10.c: Adjust. * gcc.dg/init-bad-7.c: New. From-SVN: r160418 --- gcc/ChangeLog | 15 +++++++++++++- gcc/c-typeck.c | 25 +++++++++++++----------- gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/gcc.dg/c90-const-expr-10.c | 2 +- gcc/testsuite/gcc.dg/c99-const-expr-10.c | 2 +- gcc/testsuite/gcc.dg/init-bad-7.c | 11 +++++++++++ 6 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/init-bad-7.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 86791613454..af5337296c2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,19 @@ +2010-06-08 Andrew Pinski + Shujing Zhao + + PR c/37724 + * c-typeck.c (convert_for_assignment): Call pedwarn_init if the + implicit bad conversions is initialization. + (error_init): Use gmsgid instead of msgid for argument name and change + the call for error. + (pedwarn_init): Use gmsgid instead of msgid for argument name and + change the call for pedwarn. + (warning_init): Use gmsgid instead of msgid for argument name and + change the call for warning. + 2010-06-07 Nathan Froyd - * config/mips/mips-protos.h (mips_print_operand): Delete. + * config/mips/mips-protos.h (mips_print_operand): Delete. (mips_print_operand_address): Delete. * config/mips/mips.h (mips_print_operand_punct): Delete. (PRINT_OPERAND): Delete. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 103272c2368..b2d3986e185 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -5011,7 +5011,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, pedwarn (LOCATION, OPT, AS); \ break; \ case ic_init: \ - pedwarn (LOCATION, OPT, IN); \ + pedwarn_init (LOCATION, OPT, IN); \ break; \ case ic_return: \ pedwarn (LOCATION, OPT, RE); \ @@ -5785,15 +5785,16 @@ print_spelling (char *buffer) } /* Issue an error message for a bad initializer component. - MSGID identifies the message. + GMSGID identifies the message. The component name is taken from the spelling stack. */ void -error_init (const char *msgid) +error_init (const char *gmsgid) { char *ofwhat; - error ("%s", _(msgid)); + /* The gmsgid may be a format string with %< and %>. */ + error (gmsgid); ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); if (*ofwhat) error ("(near initialization for %qs)", ofwhat); @@ -5801,15 +5802,16 @@ error_init (const char *msgid) /* Issue a pedantic warning for a bad initializer component. OPT is the option OPT_* (from options.h) controlling this warning or 0 if - it is unconditionally given. MSGID identifies the message. The + it is unconditionally given. GMSGID identifies the message. The component name is taken from the spelling stack. */ void -pedwarn_init (location_t location, int opt, const char *msgid) +pedwarn_init (location_t location, int opt, const char *gmsgid) { char *ofwhat; - - pedwarn (location, opt, "%s", _(msgid)); + + /* The gmsgid may be a format string with %< and %>. */ + pedwarn (location, opt, gmsgid); ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); if (*ofwhat) pedwarn (location, opt, "(near initialization for %qs)", ofwhat); @@ -5818,15 +5820,16 @@ pedwarn_init (location_t location, int opt, const char *msgid) /* Issue a warning for a bad initializer component. OPT is the OPT_W* value corresponding to the warning option that - controls this warning. MSGID identifies the message. The + controls this warning. GMSGID identifies the message. The component name is taken from the spelling stack. */ static void -warning_init (int opt, const char *msgid) +warning_init (int opt, const char *gmsgid) { char *ofwhat; - warning (opt, "%s", _(msgid)); + /* The gmsgid may be a format string with %< and %>. */ + warning (opt, gmsgid); ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); if (*ofwhat) warning (opt, "(near initialization for %qs)", ofwhat); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cfc229f4d39..a9b9c7a9c18 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2010-06-08 Andrew Pinski + Shujing Zhao + + PR c/37724 + * gcc.dg/c90-const-expr-10.c: Adjust. + * gcc.dg/c99-const-expr-10.c: Adjust. + * gcc.dg/init-bad-7.c: New. + 2010-06-07 Rainer Orth * lib/target-supports.exp (check_effective_target_gas): New proc. diff --git a/gcc/testsuite/gcc.dg/c90-const-expr-10.c b/gcc/testsuite/gcc.dg/c90-const-expr-10.c index bad388c90b1..30c60e31f90 100644 --- a/gcc/testsuite/gcc.dg/c90-const-expr-10.c +++ b/gcc/testsuite/gcc.dg/c90-const-expr-10.c @@ -8,7 +8,7 @@ __extension__ typedef __SIZE_TYPE__ size_t; void *p = (size_t)(void *)0; /* { dg-error "without a cast" } */ -struct s { void *a; } q = { (size_t)(void *)0 }; /* { dg-error "without a cast" } */ +struct s { void *a; } q = { (size_t)(void *)0 }; /* { dg-error "without a cast|near initialization" } */ void * f (void) { diff --git a/gcc/testsuite/gcc.dg/c99-const-expr-10.c b/gcc/testsuite/gcc.dg/c99-const-expr-10.c index 8e5a1043d29..2aca6106a47 100644 --- a/gcc/testsuite/gcc.dg/c99-const-expr-10.c +++ b/gcc/testsuite/gcc.dg/c99-const-expr-10.c @@ -6,7 +6,7 @@ /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ void *p = (__SIZE_TYPE__)(void *)0; /* { dg-error "without a cast" } */ -struct s { void *a; } q = { (__SIZE_TYPE__)(void *)0 }; /* { dg-error "without a cast" } */ +struct s { void *a; } q = { (__SIZE_TYPE__)(void *)0 }; /* { dg-error "without a cast|near initialization" } */ void * f (void) { diff --git a/gcc/testsuite/gcc.dg/init-bad-7.c b/gcc/testsuite/gcc.dg/init-bad-7.c new file mode 100644 index 00000000000..738ed605060 --- /dev/null +++ b/gcc/testsuite/gcc.dg/init-bad-7.c @@ -0,0 +1,11 @@ +/* PR c/37724 */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -pedantic" } */ + +struct f +{ + int *a; +}; + +char b[10]; +struct f g = {b}; /* { dg-warning "initialization from incompatible pointer type|near initialization for" } */