diff options
author | Martin Sebor <msebor@redhat.com> | 2016-05-20 22:23:10 +0000 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2016-05-20 22:23:10 +0000 |
commit | 0e87193b73a77a32ac49efecd517a5f516fbfc99 (patch) | |
tree | ac73cfdeb4c5483ac27c5fdb146e58e30f7020d0 /gcc/c/c-typeck.c | |
parent | 0a64c66e1eeafa31eed8d533fe4c1dcfaa09ac77 (diff) |
PR c/71115 - [4.9/5/6/7 Regression] Missing warning: excess elements
in struct initializer
gcc/c/ChangeLog:
2016-05-20 Martin Sebor <msebor@redhat.com>
PR c/71115
* c-typeck.c (error_init): Use
expansion_point_location_if_in_system_header.
(warning_init): Same.
gcc/testsuite/ChangeLog:
2016-05-20 Martin Sebor <msebor@redhat.com>
PR c/71115
* gcc.dg/init-excess-2.c: New test.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@236549 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c/c-typeck.c')
-rw-r--r-- | gcc/c/c-typeck.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 30102404284..7c9b078ed1b 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -5879,16 +5879,21 @@ error_init (location_t loc, const char *gmsgid) component name is taken from the spelling stack. */ static void -pedwarn_init (location_t location, int opt, const char *gmsgid) +pedwarn_init (location_t loc, int opt, const char *gmsgid) { char *ofwhat; bool warned; + /* Use the location where a macro was expanded rather than where + it was defined to make sure macros defined in system headers + but used incorrectly elsewhere are diagnosed. */ + source_location exploc = expansion_point_location_if_in_system_header (loc); + /* The gmsgid may be a format string with %< and %>. */ - warned = pedwarn (location, opt, gmsgid); + warned = pedwarn (exploc, opt, gmsgid); ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); if (*ofwhat && warned) - inform (location, "(near initialization for %qs)", ofwhat); + inform (exploc, "(near initialization for %qs)", ofwhat); } /* Issue a warning for a bad initializer component. @@ -5903,11 +5908,16 @@ warning_init (location_t loc, int opt, const char *gmsgid) char *ofwhat; bool warned; + /* Use the location where a macro was expanded rather than where + it was defined to make sure macros defined in system headers + but used incorrectly elsewhere are diagnosed. */ + source_location exploc = expansion_point_location_if_in_system_header (loc); + /* The gmsgid may be a format string with %< and %>. */ - warned = warning_at (loc, opt, gmsgid); + warned = warning_at (exploc, opt, gmsgid); ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); if (*ofwhat && warned) - inform (loc, "(near initialization for %qs)", ofwhat); + inform (exploc, "(near initialization for %qs)", ofwhat); } /* If TYPE is an array type and EXPR is a parenthesized string |