OSDN Git Service

PR c++/44444
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 Jun 2010 17:50:10 +0000 (17:50 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 Jun 2010 17:50:10 +0000 (17:50 +0000)
* expr.c (mark_exp_read): Handle INDIRECT_REF.
* cvt.c (convert_to_void): Handle INDIRECT_REF like
handled_component_p.

* g++.dg/warn/Wunused-var-12.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160388 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/cp/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-var-12.C [new file with mode: 0644]

index 622a793..3bfd7f1 100644 (file)
@@ -1,5 +1,10 @@
 2010-06-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/44444
+       * expr.c (mark_exp_read): Handle INDIRECT_REF.
+       * cvt.c (convert_to_void): Handle INDIRECT_REF like
+       handled_component_p.
+
        PR c++/44443
        * decl.c (initialize_local_var): If TREE_USED is set on the type,
        set also DECL_READ_P on the decl.
index 4aee151..04c068c 100644 (file)
@@ -834,7 +834,9 @@ convert_to_void (tree expr, const char *implicit, tsubst_flags_t complain)
 
       while (TREE_CODE (exprv) == COMPOUND_EXPR)
        exprv = TREE_OPERAND (exprv, 1);
-      if (DECL_P (exprv) || handled_component_p (exprv))
+      if (DECL_P (exprv)
+         || handled_component_p (exprv)
+         || TREE_CODE (exprv) == INDIRECT_REF)
        /* Expr is not being 'used' here, otherwise we whould have
           called mark_{rl}value_use use here, which would have in turn
           called mark_exp_read.  Rather, we call mark_exp_read directly
index ef5d6be..0a0ba53 100644 (file)
@@ -1,7 +1,7 @@
 /* Convert language-specific tree expression to rtl instructions,
    for GNU compiler.
    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   2000, 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2004, 2007, 2010 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -132,6 +132,7 @@ mark_exp_read (tree exp)
     case IMAGPART_EXPR:
     CASE_CONVERT:
     case ADDR_EXPR:
+    case INDIRECT_REF:
       mark_exp_read (TREE_OPERAND (exp, 0));
       break;
     case COMPOUND_EXPR:
index a2ac156..70d709e 100644 (file)
@@ -1,5 +1,8 @@
 2010-06-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/44444
+       * g++.dg/warn/Wunused-var-12.C: New test.
+
        PR c++/44443
        * c-c++-common/Wunused-var-11.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-12.C b/gcc/testsuite/g++.dg/warn/Wunused-var-12.C
new file mode 100644 (file)
index 0000000..3300cbe
--- /dev/null
@@ -0,0 +1,36 @@
+// PR c++/44444
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+struct S
+{
+  const int &u;
+  const int &v;
+  S (const int &a, const int &b) : u(a), v(b) { }
+};
+
+bool
+f1 ()
+{
+  bool t = false;
+  S z = S (1, 2);
+  t |= z.u == 1;
+  t |= z.v == 2;
+  return t;
+}
+
+void
+f2 ()
+{
+  S z = S (1, 2);
+  z.u;         // { dg-warning "no effect" }
+}
+
+int i;
+
+void
+f3 ()
+{
+  S z = S (1, 2);
+  i++, z.u;    // { dg-warning "no effect" }
+}