diff --git a/docs/doxygen/mainpages/const_cpp.h b/docs/doxygen/mainpages/const_cpp.h index dfe228d67f..4f321a79b5 100644 --- a/docs/doxygen/mainpages/const_cpp.h +++ b/docs/doxygen/mainpages/const_cpp.h @@ -171,6 +171,8 @@ Currently the following symbols exist: wxBitmapToggleButton class is available in addition to wxToggleButton.} @itemdef{wxHAS_CONFIG_TEMPLATE_RW, Defined if the currently used compiler supports template Read() and Write() methods in wxConfig.} +@itemdef{wxHAS_DEPRECATED_ATTR, Defined if C++14 @c [[deprecated]] attribute is + supported (this symbol only exists in wxWidgets 3.1.6 or later).} @itemdef{wxHAS_MEMBER_DEFAULT, Defined if the currently used compiler supports C++11 @c =default.} @itemdef{wxHAS_LARGE_FILES, Defined if wxFile supports files more than 4GB in diff --git a/include/wx/defs.h b/include/wx/defs.h index 0a5c6c158e..9a063416ed 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -573,14 +573,26 @@ typedef short int WXTYPE; /* Macros for marking functions as being deprecated. - The preferred macro in the new code is wxDEPRECATED_MSG() which allows to - explain why is the function deprecated. Almost all the existing code uses - the older wxDEPRECATED() or its variants currently, but this will hopefully - change in the future. + The preferred macro in the new code is wxDEPRECATED_ATTR() which expands to + the standard [[deprecated]] attribute if supported and allows to explain + why is the function deprecated. If supporting older compilers is important, + wxDEPRECATED_MSG() can be used as it's almost universally available and + still allows to explain the reason for the deprecation. + + However almost all the existing code uses the older wxDEPRECATED() or its + variants currently, but this will hopefully change in the future. */ +#if defined(__has_cpp_attribute) + #if __has_cpp_attribute(deprecated) + #define wxHAS_DEPRECATED_ATTR + #endif +#endif + /* The basic compiler-specific construct to generate a deprecation warning. */ -#ifdef __clang__ +#ifdef wxHAS_DEPRECATED_ATTR + #define wxDEPRECATED_DECL [[deprecated]] +#elif defined(__clang__) #define wxDEPRECATED_DECL __attribute__((deprecated)) #elif defined(__GNUC__) #define wxDEPRECATED_DECL __attribute__((deprecated)) @@ -590,13 +602,28 @@ typedef short int WXTYPE; #define wxDEPRECATED_DECL #endif +#ifdef wxHAS_DEPRECATED_ATTR + #define wxDEPRECATED_ATTR(msg) [[deprecated(msg)]] +#else + /* + Note that we can't fall back on wxDEPRECATED_DECL here, as the standard + attribute works in places where the compiler-specific one don't, + notably it can be used after enumerator declaration with MSVC, while + __declspec(deprecated) can't occur there as it can only be used before + the declaration. + */ + #define wxDEPRECATED_ATTR(msg) +#endif + /* Macro taking the deprecation message. It applies to the next declaration. If the compiler doesn't support showing the message, this degrades to a simple wxDEPRECATED(), i.e. at least gives a warning, if possible. */ -#if defined(__clang__) && defined(__has_extension) +#ifdef wxHAS_DEPRECATED_ATTR + #define wxDEPRECATED_MSG(msg) [[deprecated(msg)]] +#elif defined(__clang__) && defined(__has_extension) #if __has_extension(attribute_deprecated_with_message) #define wxDEPRECATED_MSG(msg) __attribute__((deprecated(msg))) #else diff --git a/interface/wx/defs.h b/interface/wx/defs.h index 05fb242bff..992b46c84b 100644 --- a/interface/wx/defs.h +++ b/interface/wx/defs.h @@ -1600,6 +1600,17 @@ template void wxDELETE(T*& ptr); */ template void wxDELETEA(T*& array); +/** + Expands to the standard C++14 [[deprecated]] attribute if supported. + + If not supported by the compiler, expands to nothing. If support for such + compilers is important, use wxDEPRECATED_MSG() which is almost universally + available. + + @since 3.1.6 + */ +#define wxDEPRECATED_ATTR(msg) [[deprecated(msg)]] + /** Generate deprecation warning with the given message when a function is used.