aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.cc
diff options
context:
space:
mode:
authorMartin Uecker <uecker@tugraz.at>2023-08-04 07:48:21 +0200
committerMartin Uecker <uecker@tugraz.at>2023-08-05 10:39:44 +0200
commit54be338589ea93ad4ff53d22adde476a0582537b (patch)
treef5a1196872a60798598f8460e1af6acac5daa2a6 /gcc/c/c-parser.cc
parent5b42ee2cded7c2173ea0e9f9e08dd1d9b226ed3e (diff)
downloadgcc-54be338589ea93ad4ff53d22adde476a0582537b.zip
gcc-54be338589ea93ad4ff53d22adde476a0582537b.tar.gz
gcc-54be338589ea93ad4ff53d22adde476a0582537b.tar.bz2
c: _Generic should not warn in non-active branches [PR68193,PR97100,PR110703]
To avoid false diagnostics, use c_inhibit_evaluation_warnings when a generic association is known to not match during parsing. We may still generate false positives if the default branch comes earler than a specific association that matches. PR c/68193 PR c/97100 PR c/110703 gcc/c/: * c-parser.cc (c_parser_generic_selection): Inhibit evaluation warnings branches that are known not be taken during parsing. gcc/testsuite/ChangeLog: * gcc.dg/pr68193.c: New test.
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r--gcc/c/c-parser.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 7a9fdda..57a01dc 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -9392,7 +9392,17 @@ c_parser_generic_selection (c_parser *parser)
return error_expr;
}
+ bool match = assoc.type == NULL_TREE
+ || comptypes (assoc.type, selector_type);
+
+ if (!match)
+ c_inhibit_evaluation_warnings++;
+
assoc.expression = c_parser_expr_no_commas (parser, NULL);
+
+ if (!match)
+ c_inhibit_evaluation_warnings--;
+
if (assoc.expression.value == error_mark_node)
{
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
@@ -9429,7 +9439,7 @@ c_parser_generic_selection (c_parser *parser)
match_found = associations.length ();
}
}
- else if (comptypes (assoc.type, selector_type))
+ else if (match)
{
if (match_found < 0 || matched_assoc.type == NULL_TREE)
{