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

Implement signature changes for char_traits in N2349 #3739

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 18 additions & 18 deletions stl/inc/xstring
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,27 @@ struct _Char_traits { // properties of a string or stream element
}
}

_NODISCARD static constexpr bool eq(const _Elem& _Left, const _Elem& _Right) noexcept {
_NODISCARD static constexpr bool eq(const _Elem _Left, const _Elem _Right) noexcept {
return _Left == _Right;
}

_NODISCARD static constexpr bool lt(const _Elem& _Left, const _Elem& _Right) noexcept {
_NODISCARD static constexpr bool lt(const _Elem _Left, const _Elem _Right) noexcept {
return _Left < _Right;
}

_NODISCARD static constexpr _Elem to_char_type(const int_type& _Meta) noexcept {
_NODISCARD static constexpr _Elem to_char_type(const int_type _Meta) noexcept {
return static_cast<_Elem>(_Meta);
}

_NODISCARD static constexpr int_type to_int_type(const _Elem& _Ch) noexcept {
_NODISCARD static constexpr int_type to_int_type(const _Elem _Ch) noexcept {
return static_cast<int_type>(_Ch);
}

_NODISCARD static constexpr bool eq_int_type(const int_type& _Left, const int_type& _Right) noexcept {
_NODISCARD static constexpr bool eq_int_type(const int_type _Left, const int_type _Right) noexcept {
return _Left == _Right;
}

_NODISCARD static constexpr int_type not_eof(const int_type& _Meta) noexcept {
_NODISCARD static constexpr int_type not_eof(const int_type _Meta) noexcept {
return _Meta != eof() ? _Meta : !eof();
}

Expand Down Expand Up @@ -302,27 +302,27 @@ public:
_Left = _Right;
}

_NODISCARD static constexpr bool eq(const _Elem& _Left, const _Elem& _Right) noexcept {
_NODISCARD static constexpr bool eq(const _Elem _Left, const _Elem _Right) noexcept {
return _Left == _Right;
}

_NODISCARD static constexpr bool lt(const _Elem& _Left, const _Elem& _Right) noexcept {
_NODISCARD static constexpr bool lt(const _Elem _Left, const _Elem _Right) noexcept {
return _Left < _Right;
}

_NODISCARD static constexpr _Elem to_char_type(const int_type& _Meta) noexcept {
_NODISCARD static constexpr _Elem to_char_type(const int_type _Meta) noexcept {
return _Meta;
}

_NODISCARD static constexpr int_type to_int_type(const _Elem& _Ch) noexcept {
_NODISCARD static constexpr int_type to_int_type(const _Elem _Ch) noexcept {
return _Ch;
}

_NODISCARD static constexpr bool eq_int_type(const int_type& _Left, const int_type& _Right) noexcept {
_NODISCARD static constexpr bool eq_int_type(const int_type _Left, const int_type _Right) noexcept {
return _Left == _Right;
}

_NODISCARD static constexpr int_type not_eof(const int_type& _Meta) noexcept {
_NODISCARD static constexpr int_type not_eof(const int_type _Meta) noexcept {
return _Meta != eof() ? _Meta : static_cast<int_type>(!eof());
}

Expand Down Expand Up @@ -446,27 +446,27 @@ public:
_Left = _Right;
}

_NODISCARD static constexpr bool eq(const _Elem& _Left, const _Elem& _Right) noexcept {
_NODISCARD static constexpr bool eq(const _Elem _Left, const _Elem _Right) noexcept {
return _Left == _Right;
}

_NODISCARD static constexpr bool lt(const _Elem& _Left, const _Elem& _Right) noexcept {
_NODISCARD static constexpr bool lt(const _Elem _Left, const _Elem _Right) noexcept {
return static_cast<unsigned char>(_Left) < static_cast<unsigned char>(_Right);
}

_NODISCARD static constexpr _Elem to_char_type(const int_type& _Meta) noexcept {
_NODISCARD static constexpr _Elem to_char_type(const int_type _Meta) noexcept {
return static_cast<_Elem>(_Meta);
}

_NODISCARD static constexpr int_type to_int_type(const _Elem& _Ch) noexcept {
_NODISCARD static constexpr int_type to_int_type(const _Elem _Ch) noexcept {
return static_cast<unsigned char>(_Ch);
}

_NODISCARD static constexpr bool eq_int_type(const int_type& _Left, const int_type& _Right) noexcept {
_NODISCARD static constexpr bool eq_int_type(const int_type _Left, const int_type _Right) noexcept {
return _Left == _Right;
}

_NODISCARD static constexpr int_type not_eof(const int_type& _Meta) noexcept {
_NODISCARD static constexpr int_type not_eof(const int_type _Meta) noexcept {
return _Meta != eof() ? _Meta : !eof();
}

Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ tests\GH_003105_piecewise_densities
tests\GH_003119_error_category_ctor
tests\GH_003246_cmath_narrowing
tests\GH_003617_vectorized_meow_element
tests\GH_003735_char_traits_signatures
tests\LWG2381_num_get_floating_point
tests\LWG2597_complex_branch_cut
tests\LWG3018_shared_ptr_function
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/GH_003735_char_traits_signatures/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_matrix.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cstdint>
#include <cstdio>
#include <cwchar>
#include <string>
#include <type_traits>

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

using namespace std;

// Also ensure that the member type int_type is correct for standard specializations.
STATIC_ASSERT(is_same_v<char_traits<char>::int_type, int>);
#ifdef __cpp_char8_t
STATIC_ASSERT(is_same_v<char_traits<char8_t>::int_type, unsigned int>);
#endif // __cpp_char8_t
STATIC_ASSERT(is_same_v<char_traits<char16_t>::int_type, uint_least16_t>);
STATIC_ASSERT(is_same_v<char_traits<char32_t>::int_type, uint_least32_t>);
STATIC_ASSERT(is_same_v<char_traits<wchar_t>::int_type, wint_t>);

template <class CharT>
void test_n2349_char_traits_signatures() {
using IntT = typename char_traits<CharT>::int_type;

volatile CharT c{};
volatile IntT i{};

(void) char_traits<CharT>::eq(c, c);
(void) char_traits<CharT>::lt(c, c);
(void) char_traits<CharT>::not_eof(i);
(void) char_traits<CharT>::to_char_type(i);
(void) char_traits<CharT>::to_int_type(c);
(void) char_traits<CharT>::eq_int_type(i, i);
}

void test_n2349_char_traits_signatures_all() {
test_n2349_char_traits_signatures<char>();
#ifdef __cpp_char8_t
test_n2349_char_traits_signatures<char8_t>();
#endif // __cpp_char8_t
test_n2349_char_traits_signatures<char16_t>();
test_n2349_char_traits_signatures<char32_t>();
test_n2349_char_traits_signatures<wchar_t>();
}