Total botch with assignment to function ptrs (with partial patch)

Klaus-Georg Adams Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Wed Oct 1 08:35:00 GMT 1997


g++ 2.7.2 and egcs including 970924 don't warn about any of the 6
erroneous lines in the function junk():

---snip------------------------------------------------------------
extern void cheat_ptr( int* i );
extern void cheat_ref( int& i );
struct t {
	void cheat_ref( int& i );
	void cheat_ptr( int* i );
	static void stat_ref( int& i );
	static void stat_ptr( int* i );
};
extern t t_obj;

void junk(void)
{
	void (*c_ptr)( const int* ) = &cheat_ptr;            // 1
	void (*c_ref)( const int& ) = &cheat_ref;            // 2
	void (t::*mem_ref)( const int& ) = &t_obj.cheat_ref; // 3
	void (t::*mem_ptr)( const int* ) = &t_obj.cheat_ptr; // 4
	void (*stat_ref)( const int& ) = &t_obj.stat_ref;    // 5
	void (*stat_ptr)( const int* ) = &t_obj.stat_ptr;    // 6
}
---snip------------------------------------------------------------

For 3 and 4 there is an attempt to check at gcc/cp/typeck.c, line
6370. I have tried to fool around with that, but haven't gotten it to
actually work.

1,2 and 5,6 are fixed with the appended (naive) patch.
Now it will whinge whenever the cv-qualifier in argumentlist don't
match.

-- kga
-------------------------------------------------------------------------
Klaus-Georg Adams        Email: Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Institut f. Anorg. Chemie II                           Tel: 0721 608 3485
Uni Karlsruhe
-------------------------------------------------------------------------

--- gcc/cp/typeck.c	1997/10/01 15:10:23	1.1
+++ gcc/cp/typeck.c	1997/10/01 15:19:32
@@ -1144,9 +1144,9 @@
 	    }
 	}
       /* Note backwards order due to contravariance.  */
-      if (comp_target_types (p2, p1, 1) == 0)
+      if (comptypes (p2, p1, 1) == 0)
 	{
-	  if (comp_target_types (p1, p2, 1))
+	  if (comptypes (p1, p2, 1))
 	    {
 	      warn_contravariance = 1;
 	      continue;



More information about the Gcc-bugs mailing list