Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigate non-conformance of extensions of non-reserved names by the push_macro/pop_macro mechanism #4285

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stl/inc/exception
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ _STD_END

#else // ^^^ _HAS_EXCEPTIONS / !_HAS_EXCEPTIONS vvv

#pragma push_macro("stdext")
#undef stdext

_STDEXT_BEGIN
class exception;
_STDEXT_END
Expand Down Expand Up @@ -203,6 +206,8 @@ _EXPORT_STD using _STDEXT bad_exception;

_STD_END

#pragma pop_macro("stdext")

#endif // ^^^ !_HAS_EXCEPTIONS ^^^

extern "C++" _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(_Out_ void*) noexcept;
Expand Down
6 changes: 6 additions & 0 deletions stl/inc/istream
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ public:
return this->good();
}

#pragma push_macro("ipfx")
#pragma push_macro("isfx")
#undef ipfx
#undef isfx
// TRANSITION, ABI: non-Standard ipfx() is preserved for binary compatibility
_DEPRECATE_IO_PFX_SFX bool __CLR_OR_THIS_CALL ipfx(bool _Noskip = false) {
// test stream state and skip whitespace as needed
Expand All @@ -153,6 +157,8 @@ public:

// TRANSITION, ABI: non-Standard isfx() is preserved for binary compatibility
_DEPRECATE_IO_PFX_SFX void __CLR_OR_THIS_CALL isfx() {} // perform any wrapup
#pragma pop_macro("isfx")
#pragma pop_macro("ipfx")

#ifdef _M_CEE_PURE
basic_istream& __CLR_OR_THIS_CALL operator>>(basic_istream&(__clrcall* _Pfn)(basic_istream&) ) {
Expand Down
17 changes: 17 additions & 0 deletions stl/inc/iterator
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,17 @@ struct iterator_traits<counted_iterator<_Iter>> : iterator_traits<_Iter> {

_STD_END

#pragma push_macro("stdext")
#pragma push_macro("checked_array_iterator")
#pragma push_macro("make_checked_array_iterator")
#pragma push_macro("make_unchecked_array_iterator")
#pragma push_macro("unchecked_array_iterator")
#undef stdext
#undef checked_array_iterator
#undef make_checked_array_iterator
#undef make_unchecked_array_iterator
#undef unchecked_array_iterator

_STDEXT_BEGIN
template <class _Ptr>
class _DEPRECATE_STDEXT_ARR_ITERS checked_array_iterator { // wrap a pointer with checking
Expand Down Expand Up @@ -1857,6 +1868,12 @@ _STL_RESTORE_DEPRECATED_WARNING
_STD_END
#endif // _HAS_CXX20

#pragma pop_macro("unchecked_array_iterator")
#pragma pop_macro("make_unchecked_array_iterator")
#pragma pop_macro("make_checked_array_iterator")
#pragma pop_macro("checked_array_iterator")
#pragma pop_macro("stdext")

#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma warning(pop)
Expand Down
6 changes: 6 additions & 0 deletions stl/inc/ostream
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public:
bool _Ok; // true if stream state okay at construction
};

#pragma push_macro("opfx")
#pragma push_macro("osfx")
#undef opfx
#undef osfx
// TRANSITION, ABI: non-Standard opfx() is preserved for binary compatibility
_DEPRECATE_IO_PFX_SFX bool __CLR_OR_THIS_CALL opfx() { // test stream state and flush tie stream as needed
if (!this->good()) {
Expand All @@ -155,6 +159,8 @@ public:
_DEPRECATE_IO_PFX_SFX void __CLR_OR_THIS_CALL osfx() noexcept { // perform any wrapup
_Osfx();
}
#pragma pop_macro("osfx")
#pragma pop_macro("opfx")

void __CLR_OR_THIS_CALL _Osfx() noexcept { // perform any wrapup
_TRY_BEGIN
Expand Down
22 changes: 22 additions & 0 deletions stl/inc/random
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

// TRANSITION, GH-183
#pragma push_macro("discard_block")
#pragma push_macro("linear_congruential")
#pragma push_macro("mersenne_twister")
#pragma push_macro("subtract_with_carry")
#pragma push_macro("uniform_int")
#pragma push_macro("uniform_real")
#undef discard_block
#undef linear_congruential
#undef mersenne_twister
#undef subtract_with_carry
#undef uniform_int
#undef uniform_real

#ifdef _ALLOW_RANDOM_DISTRIBUTION_CONST_OPERATOR
#define _DISTRIBUTION_CONST const
#else
Expand Down Expand Up @@ -5370,6 +5384,14 @@ _STD_END
#undef _NRAND
#undef _DISTRIBUTION_CONST

// TRANSITION, GH-183
#pragma pop_macro("uniform_real")
#pragma pop_macro("uniform_int")
#pragma pop_macro("subtract_with_carry")
#pragma pop_macro("mersenne_twister")
#pragma pop_macro("linear_congruential")
#pragma pop_macro("discard_block")

#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma warning(pop)
Expand Down
3 changes: 3 additions & 0 deletions stl/inc/typeindex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public:
return strong_ordering::equal;
}

#pragma push_macro("raw_name") // TRANSITION, GH-2195
#undef raw_name
return _CSTD strcmp(_Tptr->raw_name() + 1, _Right._Tptr->raw_name() + 1) <=> 0;
#pragma pop_macro("raw_name")
}
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
_NODISCARD bool operator!=(const type_index& _Right) const noexcept {
Expand Down
3 changes: 3 additions & 0 deletions stl/inc/typeinfo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ _STL_DISABLE_CLANG_WARNINGS

#pragma warning(disable : 4275) // non dll-interface class 'X' used as base for dll-interface class 'Y'

#pragma push_macro("raw_name") // TRANSITION, GH-2195
#undef raw_name
#include <vcruntime_typeinfo.h>
#pragma pop_macro("raw_name")

_EXPORT_STD extern "C++" class type_info; // for typeid, MSVC looks for type_info in the global namespace

Expand Down
5 changes: 4 additions & 1 deletion stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,9 @@ compiler option, or define _ALLOW_RTCc_IN_STL to suppress this error.
#define _CHRONO ::std::chrono::
#define _RANGES ::std::ranges::

// We use the stdext (standard extension) namespace to contain extensions that are not part of the current standard
// We use the stdext (standard extension) namespace to contain non-standard extensions
#pragma push_macro("stdext")
#undef stdext
#define _STDEXT_BEGIN \
_EXTERN_CXX_WORKAROUND \
namespace stdext {
Expand All @@ -1989,6 +1991,7 @@ compiler option, or define _ALLOW_RTCc_IN_STL to suppress this error.
_END_EXTERN_CXX_WORKAROUND

#define _STDEXT ::stdext::
#pragma pop_macro("stdext")

#define _CSTD ::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
#define xtime delete
#define xtime_get delete

// Test workaround for extensions of non-reserved names that can't be removed at this moment.
#define raw_name 1001

#define ipfx 1002
#define isfx 1003

#define opfx 1004
#define osfx 1005

#define checked_array_iterator 1006
#define make_checked_array_iterator 1007
#define make_unchecked_array_iterator 1008
#define unchecked_array_iterator 1009

#define discard_block 1010
#define linear_congruential 1011
#define mersenne_twister 1012
#define subtract_with_carry 1013
#define uniform_int 1014
#define uniform_real 1015

// Also test GH-2645: <yvals_core.h>: Conformance issue on [[msvc::known_semantics]]
#define msvc 1
#define known_semantics 2
Expand Down Expand Up @@ -40,3 +61,63 @@
#if empty_bases != 6
#error bad macro expansion
#endif // empty_bases != 6

#if raw_name != 1001
#error bad macro expansion
#endif // raw_name != 1001

#if ipfx != 1002
#error bad macro expansion
#endif // ipfx != 1002

#if isfx != 1003
#error bad macro expansion
#endif // isfx != 1003

#if opfx != 1004
#error bad macro expansion
#endif // opfx != 1004

#if osfx != 1005
#error bad macro expansion
#endif // osfx != 1005

#if checked_array_iterator != 1006
#error bad macro expansion
#endif // checked_array_iterator != 1006

#if make_checked_array_iterator != 1007
#error bad macro expansion
#endif // make_checked_array_iterator != 1007

#if make_unchecked_array_iterator != 1008
#error bad macro expansion
#endif // make_unchecked_array_iterator != 1008

#if unchecked_array_iterator != 1009
#error bad macro expansion
#endif // unchecked_array_iterator != 1009

#if discard_block != 1010
#error bad macro expansion
#endif // discard_block != 1010

#if linear_congruential != 1011
#error bad macro expansion
#endif // linear_congruential != 1011

#if mersenne_twister != 1012
#error bad macro expansion
#endif // mersenne_twister != 1012

#if subtract_with_carry != 1013
#error bad macro expansion
#endif // subtract_with_carry != 1013

#if uniform_int != 1014
#error bad macro expansion
#endif // uniform_int != 1014

#if uniform_real != 1015
#error bad macro expansion
#endif // uniform_real != 1015