I'm trying to compile following code using wxWidgets 3.0 library:
foo.h
#ifdef __GNUC__
#include <wx/version.h>
#if wxMAJOR_VERSION >= 3
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" //< I'm trying to disable warning
#endif // wxMAJOR_VERSION >= 3
#endif // __GNUC__
#ifdef HAVE_VARIADIC_MACROS
#undef HAVE_VARIADIC_MACROS //< this macro redefines in wx.h
#endif // HAVE_VARIADIC_MACROS
#include <wx/wx.h> //< deprecated constructor defined here
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
foo.cpp
#include "foo.h"
....
some_menu = new wxMenuItem( ... ); //< deprecated constructor
The constructor defined in file wx/menuitem.h code:
#if WXWIN_COMPATIBILITY_2_8 //< defined
// compatibility only, don't use in new code
wxDEPRECATED_CONSTRUCTOR(
wxMenuItem(wxMenu *parentMenu,
int id,
const wxString& text,
const wxString& help,
bool isCheckable,
wxMenu *subMenu = NULL)
);
#endif
Compiling with gcc 5.4.0, Ubuntu 16.04 x86_64:
g++ -o foo.os -c -I/usr/lib/x86_64-linux-gnu/wx/include/gtk2-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -g3 -Wall -Werror
...
foo.cpp:83:109: error: 'wxMenuItem::wxMenuItem(...)' is deprecated [-Werror=deprecated-declarations]
How can i fix it?
The obvious and best solution is to stop using the deprecated ctor, it's pretty simple to do, so why not?
Otherwise, I think (but I didn't test it) that you could also make it work with
#pragma
s, but you'd need to put them around your code using this ctor, because this is where the warning is generated, not around the declaration.Finally, for completeness, you could also remove
-Werror
and live with the warning but this is, of course, not the best choice.