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 method call on undefined class


Here is a patch to gcc/cp/call.c which changes the error message to
something more informative, if you try to invoke a method on an
incomplete type.
Here's a test program
class A;

void Foo(A *a)
{
  a->Fn();
  (*a).Fn();
  int g = a->m;
}
Currently the diagnostic on the first two calls are
	incomplete.ii:5: no matching function for call to `A::Fn ()'
the new diagnostic is
	incomplete.ii:5: invalid use of undefined type `class A'
the final call implicit cast to in, already gives this diagnostic

Somewhat more informative don't you think?

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
gcc/cp/ChangeLog

Mon Sep  7 12:30:05 BST 1998  Nathan Sidwell  <nathan@acm.org>

	* call.c (build_new_method_call): Issue 'incomplete type' error,
	if class is not defined.

Index: gcc/cp/call.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/call.c,v
retrieving revision 1.92.2.6
diff -b -c -3 -p -r1.92.2.6 call.c
*** call.c	1998/07/28 14:00:08	1.92.2.6
--- call.c	1998/09/07 11:29:38
*************** build_new_method_call (instance, name, a
*** 3672,3677 ****
--- 3672,3680 ----
	/* XXX will LOOKUP_SPECULATIVELY be needed when this is done?  */
	if (flags & LOOKUP_SPECULATIVELY)
	return NULL_TREE;
+       if (TYPE_SIZE (basetype) == 0)
+ 	incomplete_type_error (instance_ptr, basetype);
+       else
	cp_error ("no matching function for call to `%T::%D (%A)%V'", basetype,
		pretty_name, user_args, TREE_TYPE (TREE_TYPE (instance_ptr)));
	print_z_candidates (candidates);

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