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]

PATCH for method calls in template functions



I checked in the following patch which prevents a bogus error on:

  struct IsCompressed { };
  struct Field {
    bool IsCompressed() const { return true; }
  };
  
  template<class C>
  inline bool
  for_each(const Field& p, IsCompressed, C)
  {
    return p.IsCompressed();
  }

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

1998-07-16  Mark Mitchell  <mark@markmitchell.com>

	* semantics.c (finish_object_call_expr): Move test for the
	function called being a TYPE_DECL to ...
	* call.c (build_new_method_call): Here.

Index: testsuite/g++.old-deja/g++.pt/call1.C
===================================================================
RCS file: call1.C
diff -N call1.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- call1.C	Thu Jul 16 11:38:01 1998
***************
*** 0 ****
--- 1,13 ----
+ // Build don't link:
+ 
+ struct IsCompressed { };
+ struct Field {
+   bool IsCompressed() const { return true; }
+ };
+ 
+ template<class C>
+ inline bool
+ for_each(const Field& p, IsCompressed, C)
+ {
+   return p.IsCompressed();
+ }
Index: testsuite/g++.old-deja/g++.pt/call2.C
===================================================================
RCS file: call2.C
diff -N call2.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- call2.C	Thu Jul 16 11:38:01 1998
***************
*** 0 ****
--- 1,14 ----
+ // Build don't link:
+ 
+ struct IsCompressed { };
+ struct Field {
+ };
+ 
+ template<class C>
+ inline bool
+ for_each(const Field& p, IsCompressed, C)
+ {
+   return p.IsCompressed(); // ERROR - calling type like a method
+ }
+ 
+ template bool for_each<int>(const Field& p, IsCompressed, int); // ERROR - instantiated from here
Index: cp/semantics.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/semantics.c,v
retrieving revision 1.15
diff -c -p -r1.15 semantics.c
*** semantics.c	1998/07/12 16:55:29	1.15
--- semantics.c	1998/07/16 18:38:06
*************** finish_object_call_expr (fn, object, arg
*** 922,933 ****
    tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
    return finish_call_expr (real_fn, args);
  #else
-   if (TREE_CODE (fn) == TYPE_DECL)
-     {
-       cp_error ("calling type `%T' like a method", fn);
-       return error_mark_node;
-     }
- 
    return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
  #endif
  }
--- 922,927 ----
Index: cp/call.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/call.c,v
retrieving revision 1.92
diff -c -p -r1.92 call.c
*** call.c	1998/06/23 01:48:58	1.92
--- call.c	1998/07/16 18:38:17
*************** build_new_method_call (instance, name, a
*** 3541,3546 ****
--- 3541,3552 ----
        template_only = 1;
      }
  
+   if (TREE_CODE (name) == TYPE_DECL)
+     {
+       cp_error ("calling type `%T' like a method", name);
+       return error_mark_node;
+     }
+     
    /* If there is an extra argument for controlling virtual bases,
       remove it for error reporting.  */
    if (flags & LOOKUP_HAS_IN_CHARGE)


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