On Wed, 13 May 2020 at 09:44, Martin Oberzalek <kingleo@xxxxxx> wrote: > > 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? It used to be undefined to pass non-POD objects through ... but the C++ standard changed to make it conditionally-supported, and G++ chooses to support it, with well-defined behaviour. This was changed in https://gcc.gnu.org/g:d2f2e467c03f108a407473366c950bc2371ca00a > Is anybody interested in getting such a warning back? > Is there another way (pragma?) getting such a warning? Use -Wconditionally-supported or add: #pragma GCC diagnostic warning "-Wconditionally-supported" > 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? I doubt it, because there's a new way to get the warning, which correctly matches the G++ semantics.