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 63 - varargs in templates


Hi,
Under the obvious rule, I've installed the attached patch and test
cases. This fixes bug63.

built & tested on i686-pc-linux-gnu

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
2000-06-22  Nathan Sidwell  <nathan@codesourcery.com>

	* call.c (build_x_va_arg): Check if in a template decl.
	* pt.c (tsubst_copy, case VA_ARG_EXPR): Use build_x_va_arg.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/call.c,v
retrieving revision 1.224
diff -c -3 -p -r1.224 call.c
*** call.c	2000/06/20 15:42:54	1.224
--- call.c	2000/06/22 09:17:37
*************** build_x_va_arg (expr, type)
*** 3838,3843 ****
--- 3838,3846 ----
       tree expr;
       tree type;
  {
+   if (processing_template_decl)
+     return build_min (VA_ARG_EXPR, type, expr);
+   
    type = complete_type_or_else (type, NULL_TREE);
  
    if (expr == error_mark_node || !type)
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/pt.c,v
retrieving revision 1.443
diff -c -3 -p -r1.443 pt.c
*** pt.c	2000/06/21 16:37:06	1.443
--- pt.c	2000/06/22 09:17:42
*************** tsubst_copy (t, args, complain, in_decl)
*** 7099,7105 ****
        }
  
      case VA_ARG_EXPR:
!       return build_va_arg (tsubst_copy (TREE_OPERAND (t, 0), args, complain,
  					in_decl),
  			   tsubst (TREE_TYPE (t), args, complain, in_decl));
  
--- 7099,7105 ----
        }
  
      case VA_ARG_EXPR:
!       return build_x_va_arg (tsubst_copy (TREE_OPERAND (t, 0), args, complain,
  					in_decl),
  			   tsubst (TREE_TYPE (t), args, complain, in_decl));
  
2000-06-22  Nathan Sidwell  <nathan@codesourcery.com>

	* g++.old-deja/g++.pt/vaarg2.C: New test.
	* g++.old-deja/g++.pt/vaarg3.C: New test.

Index: testsuite/g++.old-deja/g++.pt/vaarg2.C
===================================================================
RCS file: vaarg2.C
diff -N vaarg2.C
*** /dev/null	Tue May  5 13:32:27 1998
--- vaarg2.C	Thu Jun 22 02:24:44 2000
***************
*** 0 ****
--- 1,26 ----
+ // Build don't link:
+ // Copyright (C) 2000 Free Software Foundation
+ // Contributed by Nathan Sidwell 22 June 2000 <nathan@codesourcery.com>
+ 
+ // Origin GNATS bug report 63 from Kurt Garloff <garloff@tue.nl>
+ // We attempted to expand va_arg prematurely in a template function.
+ 
+ #include <stdarg.h>
+ 
+ template <class Type>
+ void PrintArgs (Type somearg, ...)
+ { 
+ va_list argp;
+ va_start (argp, somearg);
+ Type value;
+ while ( ( value = va_arg (argp, Type) ) > 0.0)
+   continue;
+ va_end (argp);
+ }
+ 
+ int main (void)
+ {
+ double dummy = 0;
+ PrintArgs (dummy, 1.0, 2.0, 3.0, -1.0);
+ return 0;
+ }
Index: testsuite/g++.old-deja/g++.pt/vaarg3.C
===================================================================
RCS file: vaarg3.C
diff -N vaarg3.C
*** /dev/null	Tue May  5 13:32:27 1998
--- vaarg3.C	Thu Jun 22 02:24:44 2000
***************
*** 0 ****
--- 1,26 ----
+ // Build don't link:
+ // Copyright (C) 2000 Free Software Foundation
+ // Contributed by Nathan Sidwell 22 June 2000 <nathan@codesourcery.com>
+ 
+ #include <stdarg.h>
+ 
+ struct A {
+   virtual ~A () {};
+ };
+ 
+ template <class Type>
+ void PrintArgs (Type somearg, ...)
+ { 
+ va_list argp;
+ va_start (argp, somearg); // ERROR - cannot pass non-POD
+ Type value;
+ value = va_arg (argp, Type); // ERROR - cannot pass non-POD
+ va_end (argp);
+ }
+ 
+ int main (void)
+ {
+ A dummy;
+ PrintArgs (dummy, dummy); // ERROR - cannot pass non-POD
+ return 0;
+ }

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