PR c/71115 - [5/6 Regression] Missing warning: excess elements in struct initializer
Backport from trunk.
gcc/c/ChangeLog:
* c-typeck.c (error_init): Use
expansion_point_location_if_in_system_header.
(warning_init): Same.
gcc/testsuite/ChangeLog:
* gcc.dg/init-excess-2.c: New test.
* gcc.dg/Woverride-init-1.c: Adjust.
* gcc.dg/Woverride-init-2.c: Same.
From-SVN: r241878
+2016-11-05 Martin Sebor <msebor@redhat.com>
+
+ Backport from trunk.
+ PR c/71115
+ * c-typeck.c (error_init): Use
+ expansion_point_location_if_in_system_header.
+ (warning_init): Same.
+
2016-06-03 Release Manager
* GCC 5.4.0 released.
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.
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);
}
\f
/* If TYPE is an array type and EXPR is a parenthesized string
+2016-11-05 Martin Sebor <msebor@redhat.com>
+
+ Backport from trunk.
+ PR c/71115
+ * gcc.dg/init-excess-2.c: New test.
+ * gcc.dg/Woverride-init-1.c: Adjust.
+ * gcc.dg/Woverride-init-2.c: Same.
+
2016-11-03 Martin Liska <mliska@suse.cz>
Backport from mainline
struct s s0 = {
.a = 1,
.b = 2,
- .a = 3, /* { dg-warning "initialized field overwritten|near init" } */
- 4, /* { dg-warning "initialized field overwritten|near init" } */
+ .a = 3, /* { dg-warning "initialized field overwritten" } */
+ 4, /* { dg-warning "initialized field overwritten" } */
5
};
union u u0 = {
.a = 1,
- .b = 2, /* { dg-warning "initialized field overwritten|near init" } */
- .a = 3 }; /* { dg-warning "initialized field overwritten|near init" } */
+ .b = 2, /* { dg-warning "initialized field overwritten" } */
+ .a = 3 }; /* { dg-warning "initialized field overwritten" } */
int a[5] = {
[0] = 1,
[1] = 2,
- [0] = 3, /* { dg-warning "initialized field overwritten|near init" } */
+ [0] = 3, /* { dg-warning "initialized field overwritten" } */
[2] = 4
};
struct s s0 = {
.a = 1,
.b = 2,
- .a = 3, /* { dg-warning "initialized field overwritten|near init" } */
- 4, /* { dg-warning "initialized field overwritten|near init" } */
+ .a = 3, /* { dg-warning "initialized field overwritten" } */
+ 4, /* { dg-warning "initialized field overwritten" } */
5
};
union u u0 = {
.a = 1,
- .b = 2, /* { dg-warning "initialized field overwritten|near init" } */
- .a = 3 }; /* { dg-warning "initialized field overwritten|near init" } */
+ .b = 2, /* { dg-warning "initialized field overwritten" } */
+ .a = 3 }; /* { dg-warning "initialized field overwritten" } */
int a[5] = {
[0] = 1,
[1] = 2,
- [0] = 3, /* { dg-warning "initialized field overwritten|near init" } */
+ [0] = 3, /* { dg-warning "initialized field overwritten" } */
[2] = 4
};
--- /dev/null
+/* Test for diagnostics about excess initializers when using a macro
+ defined in a system header:
+ c/71115 - Missing warning: excess elements in struct initializer. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+/* { dg-require-effective-target int32plus } */
+
+#include <stddef.h>
+
+int* a[1] = {
+ 0,
+ NULL /* { dg-warning "excess elements|near init" } */
+};
+
+const char str[1] = {
+ 0,
+ NULL /* { dg-warning "excess elements|near init" } */
+};
+
+struct S {
+ int *a;
+} s = {
+ 0,
+ NULL /* { dg-warning "excess elements|near init" } */
+};
+
+struct __attribute__ ((designated_init)) S2 {
+ int *a;
+} s2 = {
+ NULL /* { dg-warning "positional initialization|near init" } */
+};
+
+union U {
+ int *a;
+} u = {
+ 0,
+ NULL /* { dg-warning "excess elements|near init" } */
+};
+
+int __attribute__ ((vector_size (16))) ivec = {
+ 0, 0, 0, 0,
+ NULL /* { dg-warning "excess elements|near init" } */
+};
+
+int* scal = {
+ 0,
+ NULL /* { dg-warning "excess elements|near init" } */
+};