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: Fix PR 9328


This patch fixes a regression in the handling of the typeof extension;
when asking for the type of a set of overloaded functions we should
issue an error, since there is no right answer.

I also improved the error handling of an OVERLOAD; we used to just
print the first function which is truly confusing if there is more
than one overloaded function.

Tested on i686-pc-linux-gnu, applied on the 3.2 branch, 3.3 branch,
and mainline.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2003-01-22  Mark Mitchell  <mark@codesourcery.com>

	PR c++/9328
	* g++.dg/ext/typeof3.C: New test.

2003-01-22  Mark Mitchell  <mark@codesourcery.com>

	PR c++/9328
	* error.c (dump_decl): For an OVERLOAD, just print the name of the
	function; it doesn't make sense to try to print its type.
	* semantics.c (finish_typeof): Issue errors about invalid uses.

Index: cp/error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/error.c,v
retrieving revision 1.196
diff -c -5 -p -r1.196 error.c
*** cp/error.c	16 Jan 2003 20:30:37 -0000	1.196
--- cp/error.c	23 Jan 2003 00:13:53 -0000
*************** dump_decl (t, flags)
*** 927,936 ****
--- 927,955 ----
        else
  	print_tree_identifier (scratch_buffer, t);
        break;
  
      case OVERLOAD:
+       if (OVL_CHAIN (t))
+ 	{
+ 	  t = OVL_CURRENT (t);
+ 	  if (DECL_CLASS_SCOPE_P (t))
+ 	    {
+ 	      dump_type (DECL_CONTEXT (t), flags);
+ 	      output_add_string (scratch_buffer, "::");
+ 	    }
+ 	  else if (DECL_CONTEXT (t))
+ 	    {
+ 	      dump_decl (DECL_CONTEXT (t), flags);
+ 	      output_add_string (scratch_buffer, "::");
+ 	    }
+ 	  dump_decl (DECL_NAME (t), flags);
+ 	  break;
+ 	}
+       
+       /* If there's only one function, just treat it like an ordinary
+ 	 FUNCTION_DECL.  */
        t = OVL_CURRENT (t);
        /* Fall through.  */
  
      case FUNCTION_DECL:
        if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.294
diff -c -5 -p -r1.294 semantics.c
*** cp/semantics.c	16 Jan 2003 20:30:41 -0000	1.294
--- cp/semantics.c	23 Jan 2003 00:13:54 -0000
*************** check_multiple_declarators ()
*** 2134,2157 ****
  
  tree
  finish_typeof (expr)
       tree expr;
  {
    if (processing_template_decl)
      {
!       tree t;
! 
!       t = make_aggr_type (TYPEOF_TYPE);
!       TYPE_FIELDS (t) = expr;
  
!       return t;
      }
  
    if (TREE_CODE (expr) == OFFSET_REF)
      expr = resolve_offset_ref (expr);
  
!   return TREE_TYPE (expr);
  }
  
  /* Compute the value of the `sizeof' operator.  */
  
  tree
--- 2134,2165 ----
  
  tree
  finish_typeof (expr)
       tree expr;
  {
+   tree type;
+ 
    if (processing_template_decl)
      {
!       type = make_aggr_type (TYPEOF_TYPE);
!       TYPE_FIELDS (type) = expr;
  
!       return type;
      }
  
    if (TREE_CODE (expr) == OFFSET_REF)
      expr = resolve_offset_ref (expr);
  
!   type = TREE_TYPE (expr);
! 
!   if (!type || type == unknown_type_node)
!     {
!       error ("type of `%E' is unknown", expr);
!       return error_mark_node;
!     }
! 
!   return type;
  }
  
  /* Compute the value of the `sizeof' operator.  */
  
  tree
Index: testsuite/g++.dg/ext/typeof3.C
===================================================================
RCS file: testsuite/g++.dg/ext/typeof3.C
diff -N testsuite/g++.dg/ext/typeof3.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/ext/typeof3.C	23 Jan 2003 00:13:55 -0000
***************
*** 0 ****
--- 1,4 ----
+ double f(double);
+ float f(float);
+ void h(typeof(f) g) {} // { dg-error "" }
+  


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