Add wxDEPRECATED_EXPORT_CORE() macro for wxTransformMatrix

wxDEPRECATED_MSG() and WXDLLIMPEXP_CORE can't be used together in the
same declaration when the former uses the standard attribute ([[...]])
and the latter uses a legacy one (__attribute__((....))), at least not
with gcc 12.

Work around this problem by defining a special new macro that combines
both attributes in a working way.

This is rather ugly, as it would seem to be better to just always define
WXDLLIMPEXP_CORE using the standard attribute, but unfortunately this
doesn't work as the standard attribute must be placed before the
function and variable declarations, while we currently use our DLL
export macros in the middle of the declaration. Maybe we can change all
the declarations doing this later, but for now this is the simplest
solution to the immediate problem.

See #22790.
This commit is contained in:
Vadim Zeitlin 2022-09-18 18:27:04 +02:00
parent 969b1fad4c
commit 2d939a3665
2 changed files with 32 additions and 4 deletions

View file

@ -697,6 +697,36 @@ typedef short int WXTYPE;
# define wxDEPRECATED_BUT_USED_INTERNALLY(x) wxDEPRECATED(x)
#endif
/*
Some gcc versions choke on __has_cpp_attribute(gnu::visibility) due to the
presence of the colon, but we only need this macro in C++ code, so just
don't define it when using C.
*/
#ifdef __cplusplus
/*
Special macro used for the classes that are exported and deprecated.
It exists because standard [[deprecated]] attribute can't be combined with
legacy __attribute__((visibility)), but we can't use [[visibility]] instead
of the latter because it can't be use in the same place in the declarations
where we use WXDLLIMPEXP_CORE. So we define this special macro which uses
the standard visibility attribute just where we can't do otherwise.
*/
#ifdef wxHAS_DEPRECATED_ATTR
#if __has_cpp_attribute(gnu::visibility)
#define wxDEPRECATED_EXPORT_CORE(msg) \
[[deprecated(msg), gnu::visibility("default")]]
#endif
#endif
#ifndef wxDEPRECATED_EXPORT_CORE
/* Fall back when nothing special is needed or available. */
#define wxDEPRECATED_EXPORT_CORE(msg) \
wxDEPRECATED_MSG(msg) WXDLLIMPEXP_CORE
#endif
#endif /* __cplusplus */
/*
Macros to suppress and restore gcc warnings, requires g++ >= 4.6 and don't
do anything otherwise.

View file

@ -38,10 +38,8 @@
// At all times m_isIdentity is set if the matrix itself is an Identity matrix.
// It is used where possible to optimize calculations.
class
#ifndef WXBUILDING
wxDEPRECATED_MSG("use wxAffineMatrix2D instead")
#endif
WXDLLIMPEXP_CORE wxTransformMatrix: public wxObject
wxDEPRECATED_EXPORT_CORE("use wxAffineMatrix2D instead")
wxTransformMatrix: public wxObject
{
public:
wxTransformMatrix();