This is the mail archive of the gcc-bugs@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 for internal error 364



Tudor --

  You write:

    The following program generates an internal error with the 971127
    snapshot:

    #include <vector>

    int
    main()
    {
	int i;
	vector<int&> v;
	v.push_back(i);
	return 0;
    }

    /home/tudor/usr/include/g++/stl_vector.h:146: Internal compiler error 364.

    Is this a known problem?

  Yes, your code is illegal. :-) You meant vector<int>, not
vector<int&>.  I've attached a patch which makes a more helpful error
message come out.  With this patch, you get:

test.cpp:7: cannot form type pointer to reference type int & during
            template instantiation 
 
-- 
Mark Mitchell		mmitchell@usa.net
Stanford University	http://www.stanford.edu

1997-12-05  Mark Mitchell  <mmitchell@usa.net>

	* pt.c (tsubst): Avoid creating pointer to reference and
	reference to reference types.

Index: gcc/cp/pt.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/pt.c,v
retrieving revision 1.2
diff -c -p -r1.2 pt.c
*** pt.c	1997/12/05 18:27:15	1.2
--- pt.c	1997/12/06 01:34:33
*************** tsubst (t, args, nargs, in_decl)
*** 2684,2698 ****
        {
  	tree r;
  	enum tree_code code;
  	if (type == TREE_TYPE (t))
  	  return t;
  
  	code = TREE_CODE (t);
! 	if (code == POINTER_TYPE)
  	  r = build_pointer_type (type);
  	else
  	  r = build_reference_type (type);
  	r = cp_build_type_variant (r, TYPE_READONLY (t), TYPE_VOLATILE (t));
  	/* Will this ever be needed for TYPE_..._TO values?  */
  	layout_type (r);
  	return r;
--- 2684,2726 ----
        {
  	tree r;
  	enum tree_code code;
+ 
  	if (type == TREE_TYPE (t))
  	  return t;
  
  	code = TREE_CODE (t);
! 	if (TREE_CODE (type) == REFERENCE_TYPE) 
! 	  {
! 	    static int   last_line = 0;
! 	    static char* last_file = 0;
! 
! 	    /* We keep track of the last time we issued this error
! 	       message to avoid spewing a ton of messages during a
! 	       single bad template instantiation.  */
! 	    if (last_line != lineno ||
! 		last_file != input_filename)
! 	      {
! 		cp_error ("cannot form type %s to reference type %T during template instantiation",
! 			  (code == POINTER_TYPE) ? "pointer" : "reference",
! 			  type);
! 		last_line = lineno;
! 		last_file = input_filename;
! 	      }
! 
! 	    /* Use the underlying type in an attempt at error
! 	       recovery; maybe the user meant vector<int> and wrote
! 	       vector<int&>, or some such.  */
! 	    if (code == REFERENCE_TYPE)
! 	      r = type;
! 	    else
! 	      r = build_pointer_type (TREE_TYPE (type));
! 	  }
! 	else if (code == POINTER_TYPE)
  	  r = build_pointer_type (type);
  	else
  	  r = build_reference_type (type);
  	r = cp_build_type_variant (r, TYPE_READONLY (t), TYPE_VOLATILE (t));
+ 
  	/* Will this ever be needed for TYPE_..._TO values?  */
  	layout_type (r);
  	return r;


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