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]

[C++ PATCH] Fix bug 1694


Hi,
I've installed this patch for bug 1694. We issued a diagnostic during
template deduction - rather than simply fail to deduce for a particular
template.

built & tested on i686-pc-linux-gnu, approved by Mark.

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-01-18  Nathan Sidwell  <nathan@codesourcery.com>

	* cp-tree.h (lookup_template_class): Add complain parm.
	* decl.c (lookup_namespace_name): Adjust call to
	lookup_template_class.
	(make_typename_type): Likewise.
	* semantics.c (finish_template_type): Likewise.
	* pt.c (lookup_template_class): Add complain parm. Adjust.
	(tsubst_aggr_type): Pass COMPLAIN down to lookup_template_class.
	(tsubst): Likewise.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.563
diff -c -3 -p -r1.563 cp-tree.h
*** cp-tree.h	2001/01/11 12:29:16	1.563
--- cp-tree.h	2001/01/18 13:53:28
*************** extern tree current_template_args		PARAM
*** 4135,4141 ****
  extern tree push_template_decl			PARAMS ((tree));
  extern tree push_template_decl_real             PARAMS ((tree, int));
  extern void redeclare_class_template            PARAMS ((tree, tree));
! extern tree lookup_template_class		PARAMS ((tree, tree, tree, tree, int));
  extern tree lookup_template_function            PARAMS ((tree, tree));
  extern int uses_template_parms			PARAMS ((tree));
  extern tree instantiate_class_template		PARAMS ((tree));
--- 4135,4141 ----
  extern tree push_template_decl			PARAMS ((tree));
  extern tree push_template_decl_real             PARAMS ((tree, int));
  extern void redeclare_class_template            PARAMS ((tree, tree));
! extern tree lookup_template_class		PARAMS ((tree, tree, tree, tree, int, int));
  extern tree lookup_template_function            PARAMS ((tree, tree));
  extern int uses_template_parms			PARAMS ((tree));
  extern tree instantiate_class_template		PARAMS ((tree));
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.738
diff -c -3 -p -r1.738 decl.c
*** decl.c	2001/01/18 09:39:07	1.738
--- decl.c	2001/01/18 13:53:32
*************** lookup_namespace_name (namespace, name)
*** 5439,5445 ****
  					 TREE_OPERAND (template_id, 1),
  					 /*in_decl=*/NULL_TREE,
  					 /*context=*/NULL_TREE,
! 					 /*entering_scope=*/0);
  	  else if (DECL_FUNCTION_TEMPLATE_P (val)
  		   || TREE_CODE (val) == OVERLOAD)
  	    val = lookup_template_function (val,
--- 5439,5446 ----
  					 TREE_OPERAND (template_id, 1),
  					 /*in_decl=*/NULL_TREE,
  					 /*context=*/NULL_TREE,
! 					 /*entering_scope=*/0,
! 	                                 /*complain=*/1);
  	  else if (DECL_FUNCTION_TEMPLATE_P (val)
  		   || TREE_CODE (val) == OVERLOAD)
  	    val = lookup_template_function (val,
*************** make_typename_type (context, name, compl
*** 5623,5629 ****
  	  return lookup_template_class (tmpl,
  					TREE_OPERAND (fullname, 1),
  					NULL_TREE, context,
! 					/*entering_scope=*/0);
  	}
        else
  	{
--- 5624,5631 ----
  	  return lookup_template_class (tmpl,
  					TREE_OPERAND (fullname, 1),
  					NULL_TREE, context,
! 					/*entering_scope=*/0,
! 	                                /*complain=*/1);
  	}
        else
  	{
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/pt.c,v
retrieving revision 1.506
diff -c -3 -p -r1.506 pt.c
*** pt.c	2001/01/18 09:56:45	1.506
--- pt.c	2001/01/18 13:53:36
*************** maybe_get_template_decl_from_type_decl (
*** 3808,3824 ****
  
     If ENTERING_SCOPE is non-zero, we are about to enter the scope of
     the class we are looking up.
  
     If the template class is really a local class in a template
     function, then the FUNCTION_CONTEXT is the function in which it is
     being instantiated.  */
  
  tree
! lookup_template_class (d1, arglist, in_decl, context, entering_scope)
       tree d1, arglist;
       tree in_decl;
       tree context;
       int entering_scope;
  {
    tree template = NULL_TREE, parmlist;
    tree t;
--- 3808,3827 ----
  
     If ENTERING_SCOPE is non-zero, we are about to enter the scope of
     the class we are looking up.
+    
+    If COMPLAIN is non-zero, issue error messages.
  
     If the template class is really a local class in a template
     function, then the FUNCTION_CONTEXT is the function in which it is
     being instantiated.  */
  
  tree
! lookup_template_class (d1, arglist, in_decl, context, entering_scope, complain)
       tree d1, arglist;
       tree in_decl;
       tree context;
       int entering_scope;
+      int complain;
  {
    tree template = NULL_TREE, parmlist;
    tree t;
*************** lookup_template_class (d1, arglist, in_d
*** 3876,3890 ****
       crash. Alternatively D1 might not be a template type at all.  */
    if (! template)
      {
!       cp_error ("`%T' is not a template", d1);
        return error_mark_node;
      }
  
    if (TREE_CODE (template) != TEMPLATE_DECL)
      {
!       cp_error ("non-template type `%T' used as a template", d1);
!       if (in_decl)
! 	cp_error_at ("for template declaration `%D'", in_decl);
        return error_mark_node;
      }
  
--- 3879,3897 ----
       crash. Alternatively D1 might not be a template type at all.  */
    if (! template)
      {
!       if (complain)
!         cp_error ("`%T' is not a template", d1);
        return error_mark_node;
      }
  
    if (TREE_CODE (template) != TEMPLATE_DECL)
      {
!       if (complain)
!         {
!           cp_error ("non-template type `%T' used as a template", d1);
!           if (in_decl)
! 	    cp_error_at ("for template declaration `%D'", in_decl);
! 	}
        return error_mark_node;
      }
  
*************** lookup_template_class (d1, arglist, in_d
*** 3898,3904 ****
  
        parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
  
!       arglist2 = coerce_template_parms (parmlist, arglist, template, 1, 1);
        if (arglist2 == error_mark_node)
  	return error_mark_node;
  
--- 3905,3912 ----
  
        parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
  
!       arglist2 = coerce_template_parms (parmlist, arglist, template,
!                                         complain, /*require_all_args=*/1);
        if (arglist2 == error_mark_node)
  	return error_mark_node;
  
*************** lookup_template_class (d1, arglist, in_d
*** 3966,3972 ****
  	       --i, t = TREE_CHAIN (t))
  	    {
  	      tree a = coerce_template_parms (TREE_VALUE (t),
! 					      arglist, template, 1, 1);
  	      SET_TMPL_ARGS_LEVEL (bound_args, i, a);
  
  	      /* We temporarily reduce the length of the ARGLIST so
--- 3974,3981 ----
  	       --i, t = TREE_CHAIN (t))
  	    {
  	      tree a = coerce_template_parms (TREE_VALUE (t),
! 					      arglist, template,
! 	                                      complain, /*require_all_args=*/1);
  	      SET_TMPL_ARGS_LEVEL (bound_args, i, a);
  
  	      /* We temporarily reduce the length of the ARGLIST so
*************** lookup_template_class (d1, arglist, in_d
*** 3985,3991 ****
  	arglist
  	  = coerce_template_parms (INNERMOST_TEMPLATE_PARMS (parmlist),
  				   INNERMOST_TEMPLATE_ARGS (arglist),
! 				   template, 1, 1);
  
        if (arglist == error_mark_node)
  	/* We were unable to bind the arguments.  */
--- 3994,4001 ----
  	arglist
  	  = coerce_template_parms (INNERMOST_TEMPLATE_PARMS (parmlist),
  				   INNERMOST_TEMPLATE_ARGS (arglist),
! 				   template,
! 	                           complain, /*require_all_args=*/1);
  
        if (arglist == error_mark_node)
  	/* We were unable to bind the arguments.  */
*************** tsubst_aggr_type (t, args, complain, in_
*** 5461,5467 ****
  	    return error_mark_node;
  
    	  r = lookup_template_class (t, argvec, in_decl, context,
! 				     entering_scope);
  
  	  return cp_build_qualified_type_real (r, TYPE_QUALS (t),
  					       complain);
--- 5471,5477 ----
  	    return error_mark_node;
  
    	  r = lookup_template_class (t, argvec, in_decl, context,
! 				     entering_scope, complain);
  
  	  return cp_build_qualified_type_real (r, TYPE_QUALS (t),
  					       complain);
*************** tsubst (t, args, complain, in_decl)
*** 6421,6427 ****
  		    r = lookup_template_class (arg, 
  					       argvec, in_decl, 
  					       DECL_CONTEXT (arg),
! 					       /*entering_scope=*/0);
  		    return cp_build_qualified_type_real (r, 
  						         TYPE_QUALS (t),
  						         complain);
--- 6431,6438 ----
  		    r = lookup_template_class (arg, 
  					       argvec, in_decl, 
  					       DECL_CONTEXT (arg),
! 					       /*entering_scope=*/0,
! 	                                       complain);
  		    return cp_build_qualified_type_real (r, 
  						         TYPE_QUALS (t),
  						         complain);
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/semantics.c,v
retrieving revision 1.187
diff -c -3 -p -r1.187 semantics.c
*** semantics.c	2001/01/18 09:35:53	1.187
--- semantics.c	2001/01/18 13:53:37
*************** finish_template_type (name, args, enteri
*** 2032,2038 ****
    tree decl;
  
    decl = lookup_template_class (name, args,
! 				NULL_TREE, NULL_TREE, entering_scope);
    if (decl != error_mark_node)
      decl = TYPE_STUB_DECL (decl);
  
--- 2032,2039 ----
    tree decl;
  
    decl = lookup_template_class (name, args,
! 				NULL_TREE, NULL_TREE,
! 	                        entering_scope, /*complain=*/1);
    if (decl != error_mark_node)
      decl = TYPE_STUB_DECL (decl);
  
// Build don't link:

// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 18 Jan 2001 <nathan@codesourcery.com>

// Bug 1694. We complained during deduction, rather than reject the deduction.

template <class T, T d> class X {};

template <class T> X<T,0> Foo (T *);
template <class T> int Foo (T const *);

void Baz (int *p1, int const *p2)
{
  int i = Foo (p1); // ERROR - cannot convert
  int j = Foo (p2);
}
void Baz (float *p1, float const *p2)
{
  int i = Foo (p1); // ok, deduction fails on X<T,0> Foo (T *)
  int j = Foo (p2);
}

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