]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix weird expression in test for clauses other than when/default/otherwise ...
authorJakub Jelinek <jakub@redhat.com>
Thu, 23 Jan 2025 10:13:52 +0000 (11:13 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 23 Jan 2025 10:13:52 +0000 (11:13 +0100)
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.

gcc/c/c-parser.cc
gcc/cp/parser.cc

index f193329099f5b0c53db695ecbfa729d8c9def74c..93da0fbea5008334b48d4d790b0d6bf06f66d71a 100644 (file)
@@ -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");
index b823a3abd65d476242bb087ddfd170017599a0d3..24322817f3ed4ed2c3b32e965cf18f8c4d5d415d 100644 (file)
@@ -51340,7 +51340,7 @@ cp_parser_omp_metadirective (cp_parser *parser, cp_token *pragma_tok,
          cp_parser_skip_to_end_of_block_or_statement (parser, true);
          goto fail;
        }
-      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");