diff options
author | Jakub Jelinek <jakub@redhat.com> | 2025-01-23 11:13:52 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2025-01-23 11:13:52 +0100 |
commit | dd14b08e2caba952c0d8ff756a84e15d83aebeff (patch) | |
tree | 542ef3f61cc645442d844565633fb8af394510d2 /gcc/c/c-parser.cc | |
parent | d19b0682f18f9f5217aee8002e3d04f8ded04ae8 (diff) | |
download | gcc-dd14b08e2caba952c0d8ff756a84e15d83aebeff.zip gcc-dd14b08e2caba952c0d8ff756a84e15d83aebeff.tar.gz gcc-dd14b08e2caba952c0d8ff756a84e15d83aebeff.tar.bz2 |
c++: Fix weird expression in test for clauses other than when/default/otherwise [PR118604]
Some clang analyzer warned about
if (!strcmp (p, "when") == 0 && !default_p)
which really looks weird, it is better to use strcmp (p, "when") != 0
or !!strcmp (p, "when"). Furthermore, as a micro optimization, it is cheaper
to evaluate default_p than calling strcmp, so that can be put first in the &&.
The C test for the same thing wasn't that weird, but I think for consistency
it is better to use the same test rather than trying to be creative.
2025-01-23 Jakub Jelinek <jakub@redhat.com>
PR c++/118604
gcc/c/
* c-parser.cc (c_parser_omp_metadirective): Rewrite
condition for clauses other than when, default and otherwise.
gcc/cp/
* parser.cc (cp_parser_omp_metadirective): Test !default_p
first and use strcmp () != 0 rather than !strcmp () == 0.
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r-- | gcc/c/c-parser.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index f193329..93da0fb 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -29069,7 +29069,7 @@ c_parser_omp_metadirective (c_parser *parser, bool *if_p) c_parser_skip_to_end_of_block_or_statement (parser, true); goto error; } - if (!(strcmp (p, "when") == 0 || default_p)) + if (!default_p && strcmp (p, "when") != 0) { error_at (match_loc, "%qs is not valid for %qs", p, "metadirective"); |