Skip to content

gsl_byte should inspect __cpp_lib_byte in addition to _HAS_STD_BYTE #821

@StephanTLavavej

Description

@StephanTLavavej

GSL/include/gsl/gsl_byte

Lines 43 to 54 in 3d56ba9

#ifndef GSL_USE_STD_BYTE
// this tests if we are under MSVC and the standard lib has std::byte and it is enabled
#if defined(_HAS_STD_BYTE) && _HAS_STD_BYTE
#define GSL_USE_STD_BYTE 1
#else // defined(_HAS_STD_BYTE) && _HAS_STD_BYTE
#define GSL_USE_STD_BYTE 0
#endif // defined(_HAS_STD_BYTE) && _HAS_STD_BYTE
#endif // GSL_USE_STD_BYTE

inspects an implementation-specific macro _HAS_STD_BYTE defined by MSVC's STL:

https://github.com/microsoft/STL/blob/447f879b136950baf3ca35dfb54c359494fa2a77/stl/inc/yvals_core.h#L475-L477

instead of the Standard feature-test macro __cpp_lib_byte:

https://github.com/microsoft/STL/blob/447f879b136950baf3ca35dfb54c359494fa2a77/stl/inc/yvals_core.h#L888-L890

GSL could inspect both, which would make it compatible with:

  • VS 2017 15.3 (which added std::byte and _HAS_STD_BYTE) through 15.7
  • VS 2017 15.8 (which added __cpp_lib_byte) through VS 2019 today
  • Future versions of VS (when GSL stops inspecting _HAS_STD_BYTE alone, VS can stop defining it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions