From c7e2d7adf0822ea58ca3d6e86fdc06572088f986 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 11 Jun 2018 17:49:30 -0400 Subject: [PATCH] PR c++/85963 - -Wunused-but-set with ?: in template. * pt.c (tsubst_copy_and_build) [COND_EXPR]: Call mark_rvalue_use. From-SVN: r261458 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/pt.c | 1 + gcc/testsuite/g++.dg/warn/Wunused-var-34.C | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-34.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9458b41..2424a3f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-06-11 Jason Merrill + + PR c++/85963 - -Wunused-but-set with ?: in template. + * pt.c (tsubst_copy_and_build) [COND_EXPR]: Call mark_rvalue_use. + 2018-06-11 Paolo Carlini * decl.c (grok_op_properties): Consistently use the location diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d8880eb..ba78d2e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18511,6 +18511,7 @@ tsubst_copy_and_build (tree t, case COND_EXPR: { tree cond = RECUR (TREE_OPERAND (t, 0)); + cond = mark_rvalue_use (cond); tree folded_cond = fold_non_dependent_expr (cond); tree exp1, exp2; diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-34.C b/gcc/testsuite/g++.dg/warn/Wunused-var-34.C new file mode 100644 index 0000000..52c7151 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-34.C @@ -0,0 +1,27 @@ +// PR c++/85963 +// { dg-additional-options -Wall } + +template +struct foo { + T val, alpha; + foo() : val(0), alpha(0) {} +}; + +template +inline void bar(const foo& A, const foo& B, foo& C) { + const bool use_alpha = true; + const T alpha = use_alpha ? (A.alpha * B.alpha) : T(0); + + C.val = A.val * B.val; + C.alpha = alpha; +} + + +int main() { + foo A,B,C; + + bar(A,B,C); + + return 0; +} + -- 2.7.4