This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/26696


There were two bugs here: first, that we didn't warn about uselessly naming a function, and then that we ICEd as a result.

The first is fixed by changing is_overloaded_fn (and get_first_fn) to look through COMPONENT_REF.

The second is fixed by replacing anything with no side effects with void_zero_node, which also should save space and time in later passes.

Tested x86_64-pc-linux-gnu, applied to trunk.
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.

Index: cp/decl.c
===================================================================
*** cp/decl.c	(revision 116703)
--- cp/decl.c	(working copy)
*************** grokdeclarator (const cp_declarator *dec
*** 7014,7021 ****
  		  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));
--- 7014,7019 ----
Index: cp/cvt.c
===================================================================
*** cp/cvt.c	(revision 116703)
--- cp/cvt.c	(working copy)
*************** convert_to_void (tree expr, const char *
*** 960,965 ****
--- 960,967 ----
  	}
        expr = build1 (CONVERT_EXPR, void_type_node, expr);
      }
+   if (! TREE_SIDE_EFFECTS (expr))
+     expr = void_zero_node;
    return expr;
  }
  
Index: cp/tree.c
===================================================================
*** cp/tree.c	(revision 116703)
--- cp/tree.c	(working copy)
*************** int
*** 853,859 ****
  is_overloaded_fn (tree x)
  {
    /* A baselink is also considered an overloaded function.  */
!   if (TREE_CODE (x) == OFFSET_REF)
      x = TREE_OPERAND (x, 1);
    if (BASELINK_P (x))
      x = BASELINK_FUNCTIONS (x);
--- 853,860 ----
  is_overloaded_fn (tree x)
  {
    /* A baselink is also considered an overloaded function.  */
!   if (TREE_CODE (x) == OFFSET_REF
!       || TREE_CODE (x) == COMPONENT_REF)
      x = TREE_OPERAND (x, 1);
    if (BASELINK_P (x))
      x = BASELINK_FUNCTIONS (x);
*************** get_first_fn (tree from)
*** 880,885 ****
--- 881,888 ----
  {
    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: testsuite/g++.dg/other/component1.C
===================================================================
*** testsuite/g++.dg/other/component1.C	(revision 116703)
--- testsuite/g++.dg/other/component1.C	(working copy)
*************** void Foo () {
*** 23,29 ****
    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" "" }
  }
--- 23,29 ----
    c.f;		        // { dg-error "statement cannot resolve" "" }
    c.f<int>;		// { dg-error "statement cannot resolve" "" }
    
!   c.g == 1;		// { dg-error "invalid" "" }
!   c.f == 1;		// { dg-error "invalid" "" }
!   c.f<int> == 1;	// { dg-error "invalid" "" }
  }
Index: testsuite/g++.dg/warn/noeffect8.C
===================================================================
*** testsuite/g++.dg/warn/noeffect8.C	(revision 0)
--- testsuite/g++.dg/warn/noeffect8.C	(revision 0)
***************
*** 0 ****
--- 1,12 ----
+ // PR c++/26696
+ 
+ struct A
+ {
+   static void f() {}
+ }; 
+ 
+ int main() 
+ {
+   A a; 
+   a.f;    			// { dg-warning "not call" }
+ }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]