re PR c++/44362 (Bogus set-but-not-used warning)
authorJakub Jelinek <jakub@redhat.com>
Fri, 4 Jun 2010 18:42:42 +0000 (20:42 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 4 Jun 2010 18:42:42 +0000 (20:42 +0200)
PR c++/44362
* call.c (build_conditional_expr): If both arg2 and arg3 are lvalues
with the same type, call mark_lvalue_use on both.

* c-c++-common/Wunused-var-10.c: New test.

Co-Authored-By: Jason Merrill <jason@redhat.com>
From-SVN: r160289

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wunused-var-10.c [new file with mode: 0644]

index b2f6cd1de99d04bf625ab2c39a8600bc89cd95b3..b949f5aacdc32e037f3906e91fb43c00b760e0b2 100644 (file)
@@ -1,3 +1,10 @@
+2010-06-04  Jakub Jelinek  <jakub@redhat.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/44362
+       * call.c (build_conditional_expr): If both arg2 and arg3 are lvalues
+       with the same type, call mark_lvalue_use on both.
+
 2010-06-03  Nathan Froyd  <froydnj@codesourcery.com>
 
        * class.c (struct vtbl_init_data_s): Remove last_init field.
index b9f1c7fd4ec7ba829917806d6a3ee6d8e2aa9455..60cc4f219dc85feea9d9ffae2f16137cb5cb7b66 100644 (file)
@@ -3839,6 +3839,8 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3,
       && same_type_p (arg2_type, arg3_type))
     {
       result_type = arg2_type;
+      mark_lvalue_use (arg2);
+      mark_lvalue_use (arg3);
       goto valid_operands;
     }
 
index 617ae6046517f65f82a239bd2979fae982351281..dd4b2c206d6e51dc35836189ec4f9a4519121b7b 100644 (file)
@@ -1,3 +1,8 @@
+2010-06-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/44362
+       * c-c++-common/Wunused-var-10.c: New test.
+
 2010-06-04  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        PR c/25880
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-10.c b/gcc/testsuite/c-c++-common/Wunused-var-10.c
new file mode 100644 (file)
index 0000000..16d5171
--- /dev/null
@@ -0,0 +1,68 @@
+/* PR c++/44362 */
+/* { dg-options "-Wunused" } */
+/* { dg-do compile } */
+
+int
+f1 (int u, int v)
+{
+  int a, b, c, d, e, f, g, h, i;
+  a = u;
+  b = v;
+  c = u;
+  d = v;
+  e = u;
+  f = v;
+  g = u == 6 ? a : b;
+  h = 0 ? c : d;
+  i = 1 ? e : f;
+  return g + h + i;
+}
+
+int
+f2 (int u, int v)
+{
+  int a, b, c, d, e, f, g, h, i;
+  a = u;
+  b = v;
+  c = u;
+  d = v;
+  e = u;
+  f = v;
+  g = u == 6 ? a + 1 : b;
+  h = 0 ? c + 1 : d;
+  i = 1 ? e + 1 : f;
+  return g + h + i;
+}
+
+int
+f3 (int u, int v)
+{
+  int a, b, c, d, e, f, g, h, i;
+  a = u;
+  b = v;
+  c = u;
+  d = v;
+  e = u;
+  f = v;
+  g = u == 6 ? a : b + 1;
+  h = 0 ? c : d + 1;
+  i = 1 ? e : f + 1;
+  return g + h + i;
+}
+
+int
+f4 (int u, int v)
+{
+  int a, c, e, g, h, i;
+  long b, d, f;
+  a = u;
+  b = v;
+  c = u;
+  d = v;
+  e = u;
+  f = v;
+  g = u == 6 ? a : b;
+  h = 0 ? c : d;
+  i = 1 ? e : f;
+  return g + h + i;
+}