re PR c++/26696 (ICE with statement forming unused static member function reference)
authorJason Merrill <jason@redhat.com>
Wed, 6 Sep 2006 17:06:00 +0000 (13:06 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 6 Sep 2006 17:06:00 +0000 (13:06 -0400)
        PR c++/26696
        * cvt.c (convert_to_void): Replace a subexpression with no side
        effects with void_zero_node.
        * tree.c (is_overloaded_fn): Look through COMPONENT_REF.
        (get_first_fn): Ditto.
        * decl.c (grokdeclarator): No need to look through COMPONENT_REF.

From-SVN: r116724

gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/cp/decl.c
gcc/cp/tree.c
gcc/testsuite/g++.dg/other/component1.C
gcc/testsuite/g++.dg/warn/noeffect8.C [new file with mode: 0644]

index 95933ac0245c979ab6df94db8d8a82890b3533c1..cd1af6f8a9153b05ad0d11e3b005261ca2e794ec 100644 (file)
@@ -1,3 +1,12 @@
+2006-09-06  Jason Merrill  <jason@redhat.com>
+
+       PR c++/26696
+       * cvt.c (convert_to_void): Replace a subexpression with no side 
+       effects with void_zero_node.
+       * tree.c (is_overloaded_fn): Look through COMPONENT_REF.
+       (get_first_fn): Ditto.
+       * decl.c (grokdeclarator): No need to look through COMPONENT_REF.
+
 2006-09-05  Jason Merrill  <jason@redhat.com>
 
        PR c++/26571
index 710bc74ccde801abf206464532435bd575ee354b..83b35d6fc763c0cfed4a9808fd6e1e8c587735cc 100644 (file)
@@ -960,6 +960,8 @@ convert_to_void (tree expr, const char *implicit)
        }
       expr = build1 (CONVERT_EXPR, void_type_node, expr);
     }
+  if (! TREE_SIDE_EFFECTS (expr))
+    expr = void_zero_node;
   return expr;
 }
 
index 542fcbe40af0b864eff4637810bfc82e048b9fad..95f0695c6f685dac75ab5c17c1206fbe92076414 100644 (file)
@@ -7014,8 +7014,6 @@ grokdeclarator (const cp_declarator *declarator,
                  tree fns = TREE_OPERAND (decl, 0);
 
                  dname = fns;
-                 if (TREE_CODE (dname) == COMPONENT_REF)
-                   dname = TREE_OPERAND (dname, 1);
                  if (TREE_CODE (dname) != IDENTIFIER_NODE)
                    {
                      gcc_assert (is_overloaded_fn (dname));
index db7e40a9cd45376c202bbf33732623b68b90ff6e..89941cc554282927427fc13cc8b51146316cb8df 100644 (file)
@@ -853,7 +853,8 @@ int
 is_overloaded_fn (tree x)
 {
   /* A baselink is also considered an overloaded function.  */
-  if (TREE_CODE (x) == OFFSET_REF)
+  if (TREE_CODE (x) == OFFSET_REF
+      || TREE_CODE (x) == COMPONENT_REF)
     x = TREE_OPERAND (x, 1);
   if (BASELINK_P (x))
     x = BASELINK_FUNCTIONS (x);
@@ -880,6 +881,8 @@ get_first_fn (tree from)
 {
   gcc_assert (is_overloaded_fn (from));
   /* A baselink is also considered an overloaded function.  */
+  if (TREE_CODE (from) == COMPONENT_REF)
+    from = TREE_OPERAND (from, 1);
   if (BASELINK_P (from))
     from = BASELINK_FUNCTIONS (from);
   return OVL_CURRENT (from);
index 80b95609d0ed2cacdf6fd202a0fd2b80d8dea979..601e019ae74d1bb2e19365e7976f61445d90b137 100644 (file)
@@ -23,7 +23,7 @@ void Foo () {
   c.f;                 // { dg-error "statement cannot resolve" "" }
   c.f<int>;            // { dg-error "statement cannot resolve" "" }
   
-  c.g == 1;            // { dg-error "invalid use of" "" }
-  c.f == 1;            // { dg-error "invalid use of" "" }
-  c.f<int> == 1;       // { dg-error "invalid use of" "" }
+  c.g == 1;            // { dg-error "invalid" "" }
+  c.f == 1;            // { dg-error "invalid" "" }
+  c.f<int> == 1;       // { dg-error "invalid" "" }
 }
diff --git a/gcc/testsuite/g++.dg/warn/noeffect8.C b/gcc/testsuite/g++.dg/warn/noeffect8.C
new file mode 100644 (file)
index 0000000..99d3688
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/26696
+
+struct A
+{
+  static void f() {}
+}; 
+
+int main() 
+{
+  A a; 
+  a.f;                         // { dg-warning "not call" }
+}