aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/semantics.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2019-08-28 02:22:29 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2019-08-28 02:22:29 +0000
commit8692693732e89806058d3b9c91132fb83661b214 (patch)
tree4d6fb359b2dfa84fd95432293af3448db1c32dd2 /gcc/cp/semantics.c
parent14da3939da3adcef84816573caa9d93c7367507e (diff)
downloadgcc-8692693732e89806058d3b9c91132fb83661b214.zip
gcc-8692693732e89806058d3b9c91132fb83661b214.tar.gz
gcc-8692693732e89806058d3b9c91132fb83661b214.tar.bz2
PR c++/81676 - bogus -Wunused warnings in constexpr if.
* semantics.c (maybe_mark_exp_read_r): New function. (finish_if_stmt): Call it on THEN_CLAUSE and ELSE_CLAUSE. * g++.dg/cpp1z/constexpr-if31.C: New test. * g++.dg/cpp1z/constexpr-if32.C: New test. From-SVN: r274982
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r--gcc/cp/semantics.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 8603e57..b61d86f 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -810,6 +810,18 @@ finish_else_clause (tree if_stmt)
ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
}
+/* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
+ read. */
+
+static tree
+maybe_mark_exp_read_r (tree *tp, int *, void *)
+{
+ tree t = *tp;
+ if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
+ mark_exp_read (t);
+ return NULL_TREE;
+}
+
/* Finish an if-statement. */
void
@@ -817,6 +829,16 @@ finish_if_stmt (tree if_stmt)
{
tree scope = IF_SCOPE (if_stmt);
IF_SCOPE (if_stmt) = NULL;
+ if (IF_STMT_CONSTEXPR_P (if_stmt))
+ {
+ /* Prevent various -Wunused warnings. We might not instantiate
+ either of these branches, so we would not mark the variables
+ used in that branch as read. */
+ cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
+ maybe_mark_exp_read_r, NULL);
+ cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
+ maybe_mark_exp_read_r, NULL);
+ }
add_stmt (do_poplevel (scope));
}