PATCH for Problem with typeid and const*

Mark Mitchell mmitchell@usa.net
Thu Mar 5 14:43:00 GMT 1998


David --

  I've attached a fix for the problem you've reported here.  Jason,
may I check this in?

    // test.h
    #include <typeinfo>
    class A
    {

    public:
	static double zero_;
	A();
	int i;
	virtual int foo(A& a);

	virtual ~A() {}
    };


    // test.cc
    #include <typeinfo>
    #include "test.h"

    A::A()
    {
	i=10;
    }

    int A::foo(A& a)
    {
	return 0;
    }


    //main.cc
    #include <typeinfo>
    #include "test.h"
    int main()
    {
	typeid(const A*);
    }


    When I compile, I receive :

    >eg++ -c -Wall test.cc ; eg++ -Wall main.cc test.o 
    Undefined                       first referenced
     symbol                             in file
    const A type_info node              /var/tmp/cca001qj1.o
    const A type_info function          /var/tmp/cca001qj1.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status
    >

-- 
Mark Mitchell		mmitchell@usa.net
Stanford University	http://www.stanford.edu

Thu Mar  5 14:27:53 1998  Mark Mitchell  <mmitchell@usa.net>

	* decl2.c (make_typeinfo_variant): New function.
	(mark_vtable_entries): Build cv-qualified variants of type-info
	functions.

Index: decl2.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl2.c,v
retrieving revision 1.49
diff -c -p -r1.49 decl2.c
*** decl2.c	1998/03/03 22:26:59	1.49
--- decl2.c	1998/03/05 22:34:03
*************** coerce_delete_type (type)
*** 2344,2349 ****
--- 2344,2370 ----
  
  extern tree abort_fndecl;
  
+ /* Build the type-information function for the CONSTP/VOLATILEP
+    qualified variant of TYPE, and ensure that it will be generated in
+    the object module.  */
+ 
+ static void
+ make_typeinfo_variant (type, constp, volatilep)
+      tree type;
+      int constp;
+      int volatilep;
+ {
+   tree fn = 
+     get_tinfo_fn (cp_build_type_variant (type, constp, volatilep));
+ 
+   /* We must generate an entry point for this function, even if it is
+      small, since it may be referenced from other modules.  */
+   TREE_ADDRESSABLE (fn) = 1;
+ 
+   /* Similarly, we must mark it as used so that it will be generated.  */
+   mark_used (fn);
+ }
+ 
  static void
  mark_vtable_entries (decl)
       tree decl;
*************** mark_vtable_entries (decl)
*** 2355,2362 ****
--- 2376,2391 ----
        tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries))
  		     : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
        tree fn = TREE_OPERAND (fnaddr, 0);
+       tree type = DECL_CONTEXT (decl);
        TREE_ADDRESSABLE (fn) = 1;
        mark_used (fn);
+       
+        /* We must also build the typeinfo functions for the
+ 	 cv-qualified variants of TYPE, as they may be requested from
+ 	 another translation unit.  */
+       make_typeinfo_variant (type, 1, 0);
+       make_typeinfo_variant (type, 0, 1);
+       make_typeinfo_variant (type, 1, 1);
      }
    skip_rtti_stuff (&entries);
  
cvs server: Diffing inc



More information about the Gcc-bugs mailing list