warning: cannot pass objects of non-POD type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello everybody,

gcc 4.4.7 warns me if I want to pass a C++ Object through a variadic function

eg:

#include <stdio.h>
#include <iostream>

int print( const char *fmt, ... )
{
  va_list argptr;

  va_start( argptr, fmt );

  char* text = va_arg(argptr, char*);

 std::cout << text << std::endl;

  va_end( argptr );

  return 0;
}

int main()
{
  std::string xx = "hello";

  print( "%s\n", xx );   //<= wrong, gcc 4.4.7 warns me here
  print( "%s\n", "123" );  //< ok, no warning
}

g++ -o p -O2 -Wall
printf.cc: In function ‘int main()’:
printf.cc:35:21: warning: cannot pass objects of non-POD type ‘std::string’ 
{aka ‘class std::__cxx11::basic_string<char>’} through ‘...’; call will abort 
at runtime
   35 |   print( "%s\n", xx );

This warning (I call it feature) disappeared in later versions. And as I 
detected: gcc can now pass a std::string object through a variadic function.

I've many variadic functions, and these are all implemented in C. They cannot 
handle C++ objects. So in my use case this is always wrong.

I'm wondering why this warning disapeared, and if somebody else is missing it?

Is anybody interested in getting such a warning back?
Is there another way (pragma?) getting such a warning?

I've created a patch, to get this warning back. Is anybody interested in such 
a patch, and how are the chances to get this in g++ as an opt in feature?

Any thoughts?

Regards, Martin

-- 
2*Pi || !(2*Pi) this == ?






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux