gcc-2.95.2 Odd warning on Sparc/Solaris7

Munagala Ramanath Munagala.Ramanath@postx.com
Sun Oct 15 15:04:00 GMT 2000


Hi,

The following simple program produces odd warnings that:
    "warning: cannot pass objects of type `A' through `...'"
and the resulting executable prints wrong results; but if the
copy constructor is removed, the warnings go away and the
program works as expected.

I'm puzzled as to why an empty copy constructor should
have this effect; is this a bug in the compiler or is there something in
the standard that requires this behavior ?

Thanks.

Ram

//----------------------------------------------------------------------
// gcc-2.95.2 Sparc/Solaris7 emits warnings and the resulting executable
// prints wrong values. If the copy constructor in A is removed everything
// works as expected.
//
#include <stdio.h>
#include <stdarg.h>

struct A {
    A( int j ) : i(j) {}
    // if this copy constructor is removed, the warnings disappear and the
code
    // works; with it, we get warnings like this:
    //     warning: cannot pass objects of type `A' through `...'
    //
    A( const A& a ) {};
	int i;
};

void
f( int i, ... )
{
    va_list ap;
	va_start( ap, i );
	A a = va_arg( ap, A );  // warning here
	printf( "f(): i = %d, a.i = %d\n", i, a.i );
	va_end(ap);
}

int
main( int, char *[] )
{
    A b( 9 );
	f( 8, b );    // warning here
    
    return 0;
}



More information about the Gcc mailing list