]> 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>
Thu, 20 Jun 2024 13:07:40 +0000 (15:07 +0200)
commit6ec50f5b9a8842f92d65dbd8fcc546f0f6902585
tree2aa9a0cc5e0f4dafe45296234c6c27efa8208d34
parent043d5fc707842c9b26ba69650e15be73c57f7a1d
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.c (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.c
gcc/testsuite/g++.dg/ext/pr114691.C [new file with mode: 0644]