Skip to content

Commit 2c6d6c1

Browse files
bpo-19569: Add a macro to suppress deprecation warnings (GH-9004)
Co-authored-by: Arfrever Frehtes Taifersar Arahesis <[email protected]> (cherry picked from commit de4304d) Co-authored-by: Zackery Spytz <[email protected]>
1 parent 7795ae8 commit 2c6d6c1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Include/pyport.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,26 @@ extern "C" {
513513
#define Py_DEPRECATED(VERSION_UNUSED)
514514
#endif
515515

516+
#if defined(__clang__)
517+
#define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push")
518+
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
519+
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
520+
#define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop")
521+
#elif defined(__GNUC__) \
522+
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
523+
#define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push")
524+
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
525+
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
526+
#define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop")
527+
#elif defined(_MSC_VER)
528+
#define _Py_COMP_DIAG_PUSH __pragma(warning(push))
529+
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996))
530+
#define _Py_COMP_DIAG_POP __pragma(warning(pop))
531+
#else
532+
#define _Py_COMP_DIAG_PUSH
533+
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
534+
#define _Py_COMP_DIAG_POP
535+
#endif
516536

517537
/* _Py_HOT_FUNCTION
518538
* The hot attribute on a function is used to inform the compiler that the
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add the private macros ``_Py_COMP_DIAG_PUSH``,
2+
``_Py_COMP_DIAG_IGNORE_DEPR_DECLS``, and ``_Py_COMP_DIAG_POP``.

0 commit comments

Comments
 (0)