bool match = assoc.type == NULL_TREE
|| comptypes (assoc.type, selector_type);
- if (!match)
+ if (!match || matched_assoc.type != NULL_TREE)
c_inhibit_evaluation_warnings++;
in_generic++;
assoc.expression = c_parser_expr_no_commas (parser, NULL);
- if (!match)
- c_inhibit_evaluation_warnings--;
+ if (!match || matched_assoc.type != NULL_TREE)
+ c_inhibit_evaluation_warnings--;
in_generic--;
if (!match)
pop_maybe_used (!flag_isoc23);
&& pedwarn (loc, OPT_Wpedantic,
"ISO C forbids casting nonscalar to the same type"))
;
- else if (warn_useless_cast)
+ else if (warn_useless_cast && c_inhibit_evaluation_warnings == 0)
warning_at (loc, OPT_Wuseless_cast,
"useless cast to type %qT", type);
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Wuseless-cast" } */
+
+
+static int i = _Generic(0., int: (int)0, default: 0);
+static int j = _Generic(0, int: 0, default: (int)0, float: 0);
+static int k = _Generic(0, default: 0, int: (int)0); /* { dg-warning "useless" } */
+
+/* If the active assocation cames later than the default, we do
+ not know that it is unused. */
+// static int l = _Generic(0, default: (int)0, int: 0);
+