Skip to content

<yvals_core.h>: Use Standard _Pragma #659

@StephanTLavavej

Description

@StephanTLavavej

In <yvals_core.h>, the STL's central internal header, we define internal helper macros for temporarily suppressing [[deprecated]] warnings:

STL/stl/inc/yvals_core.h

Lines 448 to 468 in 811c8c1

// clang-format off
#ifndef _STL_DISABLE_DEPRECATED_WARNING
#ifdef __clang__
#define _STL_DISABLE_DEPRECATED_WARNING \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
#else // __clang__
#define _STL_DISABLE_DEPRECATED_WARNING \
__pragma(warning(push)) \
__pragma(warning(disable : 4996)) // was declared deprecated
#endif // __clang__
#endif // _STL_DISABLE_DEPRECATED_WARNING
// clang-format on
#ifndef _STL_RESTORE_DEPRECATED_WARNING
#ifdef __clang__
#define _STL_RESTORE_DEPRECATED_WARNING _Pragma("clang diagnostic pop")
#else // __clang__
#define _STL_RESTORE_DEPRECATED_WARNING __pragma(warning(pop))
#endif // __clang__
#endif // _STL_RESTORE_DEPRECATED_WARNING

For Clang, this uses Standard _Pragma to emit a #pragma directive within a macro. For MSVC, this uses non-Standard __pragma.

Our general rule is to avoid non-Standard extensions unless they're necessary. As of VS 2019 16.6 Preview 2, which the STL now requires, MSVC supports Standard _Pragma, so we should use it here. (We still need #ifdef __clang__ logic because Clang and MSVC need different syntax to suppress the [[deprecated]] warning.)

Note: Standard _Pragma takes a string while non-Standard __pragma doesn't, as the existing code demonstrates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething can be improvedfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions