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 1638


I've installed the attached patch for bug 1638 where we didn't
check whether a function template instantiation had a void parameter.
I also discovered that tsubst_decl didn't pass the decl being tsubst
down to its callees as in_decl, which would be the sensible thing to
do - so I did that too.

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-23  Nathan Sidwell  <nathan@codesourcery.com>

	* pt.c (tsubst_decl): Remove IN_DECL parameter.
	(tsubst_arg_types): Check parameter is not void.
	(tsubst): Adjust tsubst_decl call.

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/pt.c,v
retrieving revision 1.509
diff -c -3 -p -r1.509 pt.c
*** pt.c	2001/01/22 13:51:42	1.509
--- pt.c	2001/01/23 11:19:31
*************** static tree most_specialized_class PARAM
*** 149,155 ****
  static void set_mangled_name_for_template_decl PARAMS ((tree));
  static int template_class_depth_real PARAMS ((tree, int));
  static tree tsubst_aggr_type PARAMS ((tree, tree, int, tree, int));
! static tree tsubst_decl PARAMS ((tree, tree, tree, tree));
  static tree tsubst_arg_types PARAMS ((tree, tree, int, tree));
  static tree tsubst_function_type PARAMS ((tree, tree, int, tree));
  static void check_specialization_scope PARAMS ((void));
--- 149,155 ----
  static void set_mangled_name_for_template_decl PARAMS ((tree));
  static int template_class_depth_real PARAMS ((tree, int));
  static tree tsubst_aggr_type PARAMS ((tree, tree, int, tree, int));
! static tree tsubst_decl PARAMS ((tree, tree, tree));
  static tree tsubst_arg_types PARAMS ((tree, tree, int, tree));
  static tree tsubst_function_type PARAMS ((tree, tree, int, tree));
  static void check_specialization_scope PARAMS ((void));
*************** tsubst_default_arguments (fn)
*** 5553,5571 ****
  
  /* Substitute the ARGS into the T, which is a _DECL.  TYPE is the
     (already computed) substitution of ARGS into TREE_TYPE (T), if
!    appropriate.  Return the result of the substitution.  IN_DECL is as
!    for tsubst.  */
  
  static tree
! tsubst_decl (t, args, type, in_decl)
       tree t;
       tree args;
       tree type;
-      tree in_decl;
  {
    int saved_lineno;
    const char *saved_filename;
    tree r = NULL_TREE;
  
    /* Set the filename and linenumber to improve error-reporting.  */
    saved_lineno = lineno;
--- 5553,5570 ----
  
  /* Substitute the ARGS into the T, which is a _DECL.  TYPE is the
     (already computed) substitution of ARGS into TREE_TYPE (T), if
!    appropriate.  Return the result of the substitution.  */
  
  static tree
! tsubst_decl (t, args, type)
       tree t;
       tree args;
       tree type;
  {
    int saved_lineno;
    const char *saved_filename;
    tree r = NULL_TREE;
+   tree in_decl = t;
  
    /* Set the filename and linenumber to improve error-reporting.  */
    saved_lineno = lineno;
*************** tsubst_arg_types (arg_types, args, compl
*** 6117,6122 ****
--- 6116,6131 ----
    type = tsubst (TREE_VALUE (arg_types), args, complain, in_decl);
    if (type == error_mark_node)
      return error_mark_node;
+   if (VOID_TYPE_P (type))
+     {
+       if (complain)
+         {
+           cp_error ("invalid parameter type `%T'", type);
+           if (in_decl)
+             cp_error_at ("in declaration `%D'", in_decl);
+         }
+       return error_mark_node;
+     }
  
    /* Do array-to-pointer, function-to-pointer conversion, and ignore
       top-level qualifiers as required.  */
*************** tsubst (t, args, complain, in_decl)
*** 6288,6294 ****
      return error_mark_node;
  
    if (DECL_P (t))
!     return tsubst_decl (t, args, type, in_decl);
  
    switch (TREE_CODE (t))
      {
--- 6297,6303 ----
      return error_mark_node;
  
    if (DECL_P (t))
!     return tsubst_decl (t, args, type);
  
    switch (TREE_CODE (t))
      {
// Build don't link:
// 
// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 19 Jan 2001 <nathan@codesourcery.com>

// Bug 1638. We failed to check if a function instantiation produced a void
// parameter type.

template <class T> struct S
{
  int f (T);    // ERROR - void type
};

void foo ()
{
  S<void> s;
}

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