]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix bogus warnings about ignored annotations [PR114691]
authorJakub Jelinek <jakub@redhat.com>
Fri, 12 Apr 2024 18:53:10 +0000 (20:53 +0200)
committerJakub Jelinek <jakub@redhat.com>
Sun, 21 Apr 2024 04:08:06 +0000 (06:08 +0200)
commited7be7ba6f125cfda7ad07263213cbe02b7e7ced
tree7690582b57d1e14aa0747791d9c9addad2472949
parent7a1a52934a2ab9ac9205a3a4d5b82a672fefba7e
c++: Fix bogus warnings about ignored annotations [PR114691]

The middle-end warns about the ANNOTATE_EXPR added for while/for loops
if they declare a var inside of the loop condition.
This is because the assumption is that ANNOTATE_EXPR argument is used
immediately in a COND_EXPR (later GIMPLE_COND), but simplify_loop_decl_cond
wraps the ANNOTATE_EXPR inside of a TRUTH_NOT_EXPR, so it no longer
holds.

The following patch fixes that by adding the TRUTH_NOT_EXPR inside of the
ANNOTATE_EXPR argument if any.

2024-04-12  Jakub Jelinek  <jakub@redhat.com>

PR c++/114691
* semantics.cc (simplify_loop_decl_cond): Use cp_build_unary_op with
TRUTH_NOT_EXPR on ANNOTATE_EXPR argument (if any) rather than
ANNOTATE_EXPR itself.

* g++.dg/ext/pr114691.C: New test.

(cherry picked from commit 91146346f57cc54dfeb2669347edd0eb3d13af7f)
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/ext/pr114691.C [new file with mode: 0644]