object of type TYPE. */
void
-maybe_warn_string_init (tree type, struct c_expr expr)
+maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
{
if (pedantic
&& TREE_CODE (type) == ARRAY_TYPE
&& TREE_CODE (expr.value) == STRING_CST
&& expr.original_code != STRING_CST)
- pedwarn_init (input_location, OPT_Wpedantic,
+ pedwarn_init (loc, OPT_Wpedantic,
"array initialized from parenthesized string constant");
}
/* This macro is used to emit diagnostics to ensure that all format
strings are complete sentences, visible to gettext and checked at
compile time. */
-#define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \
+#define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \
do { \
switch (errtype) \
{ \
case ic_argpass: \
if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \
inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \
- ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \
+ ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \
"expected %qT but argument is of type %qT", \
type, rhstype); \
break; \
pedwarn_init (LOCATION, OPT, IN); \
break; \
case ic_return: \
- pedwarn (LOCATION, OPT, RE); \
+ pedwarn (LOCATION, OPT, RE); \
break; \
default: \
gcc_unreachable (); \
expr.value = inside_init;
expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
expr.original_type = NULL;
- maybe_warn_string_init (type, expr);
+ maybe_warn_string_init (init_loc, type, expr);
if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
pedwarn_init (init_loc, OPT_Wpedantic,
if (constructor_depth > 2)
error_init (loc, "initialization of flexible array member in a nested context");
else
- pedwarn_init (input_location, OPT_Wpedantic,
+ pedwarn_init (loc, OPT_Wpedantic,
"initialization of a flexible array member");
/* We have already issued an error message for the existence
void
set_init_index (location_t loc, tree first, tree last,
- struct obstack * braced_init_obstack)
+ struct obstack *braced_init_obstack)
{
if (set_designator (loc, 1, braced_init_obstack))
return;
{
first = c_fully_fold (first, false, NULL);
if (TREE_CODE (first) == INTEGER_CST)
- pedwarn_init (input_location, OPT_Wpedantic,
+ pedwarn_init (loc, OPT_Wpedantic,
"array index in initializer is not "
"an integer constant expression");
}
{
last = c_fully_fold (last, false, NULL);
if (TREE_CODE (last) == INTEGER_CST)
- pedwarn_init (input_location, OPT_Wpedantic,
+ pedwarn_init (loc, OPT_Wpedantic,
"array index in initializer is not "
"an integer constant expression");
}
if (constructor_fields == 0)
{
- pedwarn_init (input_location, 0,
+ pedwarn_init (loc, 0,
"excess elements in union initializer");
break;
}
&& (tree_int_cst_lt (constructor_max_index, constructor_index)
|| integer_all_onesp (constructor_max_index)))
{
- pedwarn_init (input_location, 0,
+ pedwarn_init (loc, 0,
"excess elements in array initializer");
break;
}
always have a fixed size derived from their type. */
if (tree_int_cst_lt (constructor_max_index, constructor_index))
{
- pedwarn_init (input_location, 0,
+ pedwarn_init (loc, 0,
"excess elements in vector initializer");
break;
}
else if (constructor_type != error_mark_node
&& constructor_fields == 0)
{
- pedwarn_init (input_location, 0,
+ pedwarn_init (loc, 0,
"excess elements in scalar initializer");
break;
}
{
low_value = c_fully_fold (low_value, false, NULL);
if (TREE_CODE (low_value) == INTEGER_CST)
- pedwarn (input_location, OPT_Wpedantic,
+ pedwarn (loc, OPT_Wpedantic,
"case label is not an integer constant expression");
}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -Wpedantic" } */
+/* { dg-prune-output ".*near initialization for.*" } */
+
+typedef unsigned vec __attribute__ ((vector_size (2 * sizeof (int))));
+union u { int a; double d; };
+struct S { int i; char fam[]; };
+
+int i;
+vec v = { 1, 2, 3 }; /* { dg-warning "17:excess elements in vector initializer" } */
+int a1 = { 1, 2 }; /* { dg-warning "15:excess elements in scalar initializer" } */
+int a2[2] = { 1, 2, 3 }; /* { dg-warning "21:excess elements in array initializer" } */
+int a3[] = { [1 ? 1 : i] = 0 }; /* { dg-warning "15:array index in initializer is not an integer constant expression" } */
+int a4[] = { [1 ... 1 ? 2 : i] = 0 }; /* { dg-warning "15:array index in initializer is not an integer constant expression" } */
+char a5[] = ("lol"); /* { dg-warning "13:array initialized from parenthesized string constant" } */
+char a6[] = { ("foo") }; /* { dg-warning "13:array initialized from parenthesized string constant" } */
+char *a7 = (char []) { ("bar") }; /* { dg-warning "12:array initialized from parenthesized string constant" } */
+union u u = { 1, 1.0 }; /* { dg-warning "18:excess elements in union initializer" } */
+struct S s = { 1, 2 }; /* { dg-warning "14:initialization of a flexible array member" } */