Patch for too lenient handling of pointer-to-member conversions

Klaus-Georg Adams Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Fri Feb 13 05:01:00 GMT 1998


Hi Mark,

Does your patch
Wed Feb 11 15:54:18 1998  Mark Mitchell  

        * typeck.c (build_ptrmemfunc): Typecheck pointer-to-member
        conversions.

flag cases like the following:

//
// Demonstrate the lack of checking in assignment to member
// function pointers.

#include <iostream.h>

struct t {
	void cheat( int& i ) { ++i; }
};

int main()
{
	void (t::*member)( const int& ) = &t::cheat;
	t t2;
	const int i=1;
	int j=1;
	(t2.*member)( i );
	(t2.*member)( j );
	cout << " i is: " << i << endl
	     << " j is: " << j << endl;
	return 0;
}

or 

//
// Demonstrate the lack of checking in assignment to function
// pointers. Note: gcc flags this, g++ doesn't.

#include <stdio.h>

void cheat( int* i ) { ++(*i); }

int main()
{
	void (*cheater)( const int* ) = &cheat;
	const int i=1;
	int j=1;
	(*cheater)( &i );
	(*cheater)( &j );
	printf( " i is: %i\n j is: %i\n", i, j );
	return 0;
}

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



More information about the Gcc-bugs mailing list