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]
Other format: [Raw text]

Re: cannot pass objects of non-POD type [] through '...'


Hi,

here are short sample program and some compiler outputs ...

Maybe someone can explain this behaviour, since I believe THIS should really
be possible?!

regards
	Daniel


------------------------------------

#include <iostream>
#include <cstdarg>

using namespace std;

ostream& func(ostream& stream, ...) {

	va_list va;
	va_start(va, stream);

	// get anything from '...'

	va_end(va);

	stream << "Hello world" << endl;

	return stream;
}

int main(void) {
	func(cout);
	return 0;
}

/*

Some compiler versions and their results from above sample:

#################################################################

OS: Solaris 8 (sparc)

> g++ -v
Reading specs from /opt/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/specs
gcc version 2.95.3 20010315 (release)

> g++ -O2 -Wall nonPOD.cpp
nonPOD.cpp:10: warning: cannot pass objects of type `ostream' through `...'

>./a.out
Hello world
>


#################################################################

OS: Linux/GNU (intel)

> g++ -v
Thread model: posix
gcc version 3.2

> g++ -O2 -Wall nonPOD.cpp
nonPOD.cpp: In function `std::ostream& func(std::ostream&, ...)':
nonPOD.cpp:10: cannot pass objects of non-POD type `struct
   std::basic_ostream<char, std::char_traits<char> >' through `...'
nonPOD.cpp:10: warning: second parameter of `va_start' not last named
argument

> (no binary)

#################################################################

OS: Solaris 8 (sparc)

> g++ -v
Thread model: posix
gcc version 3.2.2

(Remark: I already replaced 3.2.2 by 3.3, this output is 'remembered')

> g++ -O2 -Wall nonPOD.cpp
nonPOD.cpp: In function `std::ostream& func(std::ostream&, ...)':
nonPOD.cpp:10: cannot pass objects of non-POD type `struct
   std::basic_ostream<char, std::char_traits<char> >' through `...'
nonPOD.cpp:10: warning: second parameter of `va_start' not last named
argument

> (no binary)


#################################################################

OS: Solaris 8 (sparc)

> g++ -v
Thread model: posix
gcc version 3.3

>g++ -O2 -Wall nonPOD.cpp
nonPOD.cpp: In function `std::ostream& func(std::ostream&, ...)':
nonPOD.cpp:10: warning: cannot pass objects of non-POD type `struct
   std::basic_ostream<char, std::char_traits<char> >' through `...'; call
will
   abort at runtime
nonPOD.cpp:10: warning: second parameter of `va_start' not last named
argument

>./a.out
Hello world
>

*/





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