[libcxx-commits] [libcxx] 2928b23 - [NFC][libc++] char_traits code cleanups.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 31 13:18:20 PDT 2022
Author: Mark de Wever
Date: 2022-08-31T22:18:10+02:00
New Revision: 2928b230ce0e23b07c57470af5b830019b314951
URL: https://github.com/llvm/llvm-project/commit/2928b230ce0e23b07c57470af5b830019b314951
DIFF: https://github.com/llvm/llvm-project/commit/2928b230ce0e23b07c57470af5b830019b314951.diff
LOG: [NFC][libc++] char_traits code cleanups.
These cleanups were identified while working on D130295.
Reviewed By: #libc, ldionne, philnik
Differential Revision: https://reviews.llvm.org/D131185
Added:
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.compile.pass.cpp
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.compile.pass.cpp
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.compile.pass.cpp
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.compile.pass.cpp
Modified:
libcxx/include/__string/char_traits.h
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/types.compile.pass.cpp
Removed:
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.pass.cpp
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.pass.cpp
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.pass.cpp
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.pass.cpp
################################################################################
diff --git a/libcxx/include/__string/char_traits.h b/libcxx/include/__string/char_traits.h
index 3182ce310abe..a35642bcbdc5 100644
--- a/libcxx/include/__string/char_traits.h
+++ b/libcxx/include/__string/char_traits.h
@@ -40,11 +40,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _CharT>
struct _LIBCPP_TEMPLATE_VIS char_traits
{
- typedef _CharT char_type;
- typedef int int_type;
- typedef streamoff off_type;
- typedef streampos pos_type;
- typedef mbstate_t state_type;
+ using char_type = _CharT;
+ using int_type = int;
+ using off_type = streamoff;
+ using pos_type = streampos;
+ using state_type = mbstate_t;
static inline void _LIBCPP_CONSTEXPR_SINCE_CXX17
assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
@@ -189,11 +189,11 @@ _CharT* __char_traits_move(_CharT* __dest, const _CharT* __source, size_t __n) _
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<char>
{
- typedef char char_type;
- typedef int int_type;
- typedef streamoff off_type;
- typedef streampos pos_type;
- typedef mbstate_t state_type;
+ using char_type = char;
+ using int_type = int;
+ using off_type = streamoff;
+ using pos_type = streampos;
+ using state_type = mbstate_t;
#if _LIBCPP_STD_VER > 17
using comparison_category = strong_ordering;
#endif
@@ -306,14 +306,14 @@ char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a)
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
{
- typedef wchar_t char_type;
- typedef wint_t int_type;
- typedef streamoff off_type;
- typedef streampos pos_type;
- typedef mbstate_t state_type;
-# if _LIBCPP_STD_VER > 17
+ using char_type = wchar_t;
+ using int_type = wint_t;
+ using off_type = streamoff;
+ using pos_type = streampos;
+ using state_type = mbstate_t;
+#if _LIBCPP_STD_VER > 17
using comparison_category = strong_ordering;
-# endif
+#endif
static inline _LIBCPP_CONSTEXPR_SINCE_CXX17
void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
@@ -425,14 +425,14 @@ char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
{
- typedef char8_t char_type;
- typedef unsigned int int_type;
- typedef streamoff off_type;
- typedef u8streampos pos_type;
- typedef mbstate_t state_type;
-# if _LIBCPP_STD_VER > 17
+ using char_type = char8_t;
+ using int_type = unsigned int;
+ using off_type = streamoff;
+ using pos_type = u8streampos;
+ using state_type = mbstate_t;
+#if _LIBCPP_STD_VER > 17
using comparison_category = strong_ordering;
-# endif
+#endif
static inline constexpr void assign(char_type& __c1, const char_type& __c2) noexcept
{__c1 = __c2;}
@@ -529,11 +529,11 @@ char_traits<char8_t>::find(const char_type* __s, size_t __n, const char_type& __
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
{
- typedef char16_t char_type;
- typedef uint_least16_t int_type;
- typedef streamoff off_type;
- typedef u16streampos pos_type;
- typedef mbstate_t state_type;
+ using char_type = char16_t;
+ using int_type = uint_least16_t;
+ using off_type = streamoff;
+ using pos_type = u16streampos;
+ using state_type = mbstate_t;
#if _LIBCPP_STD_VER > 17
using comparison_category = strong_ordering;
#endif
@@ -623,11 +623,11 @@ char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& _
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t>
{
- typedef char32_t char_type;
- typedef uint_least32_t int_type;
- typedef streamoff off_type;
- typedef u32streampos pos_type;
- typedef mbstate_t state_type;
+ using char_type = char32_t;
+ using int_type = uint_least32_t;
+ using off_type = streamoff;
+ using pos_type = u32streampos;
+ using state_type = mbstate_t;
#if _LIBCPP_STD_VER > 17
using comparison_category = strong_ordering;
#endif
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.compile.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.compile.pass.cpp
new file mode 100644
index 000000000000..48ee0017b1ec
--- /dev/null
+++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.compile.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// using char_type = char;
+// using int_type = int;
+// using off_type = streamoff;
+// using pos_type = streampos;
+// using state_type = mbstate_t;
+// using comparison_category = strong_ordering;
+
+#include <string>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(std::is_same<std::char_traits<char>::char_type, char>::value, "");
+static_assert(std::is_same<std::char_traits<char>::int_type, int>::value, "");
+static_assert(std::is_same<std::char_traits<char>::off_type, std::streamoff>::value, "");
+static_assert(std::is_same<std::char_traits<char>::pos_type, std::streampos>::value, "");
+static_assert(std::is_same<std::char_traits<char>::state_type, std::mbstate_t>::value, "");
+#if TEST_STD_VER > 17
+static_assert(std::is_same_v<std::char_traits<char>::comparison_category, std::strong_ordering>);
+#endif
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.pass.cpp
deleted file mode 100644
index f3b2505ba9a2..000000000000
--- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.pass.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <string>
-
-// template<> struct char_traits<char>
-
-// typedef char char_type;
-// typedef int int_type;
-// typedef streamoff off_type;
-// typedef streampos pos_type;
-// typedef mbstate_t state_type;
-// using comparison_category = strong_ordering;
-
-#include <string>
-#include <type_traits>
-
-#include "test_macros.h"
-
-int main(int, char**)
-{
- static_assert((std::is_same<std::char_traits<char>::char_type, char>::value), "");
- static_assert((std::is_same<std::char_traits<char>::int_type, int>::value), "");
- static_assert((std::is_same<std::char_traits<char>::off_type, std::streamoff>::value), "");
- static_assert((std::is_same<std::char_traits<char>::pos_type, std::streampos>::value), "");
- static_assert((std::is_same<std::char_traits<char>::state_type, std::mbstate_t>::value), "");
-#if TEST_STD_VER > 17
- static_assert(std::is_same_v<std::char_traits<char>::comparison_category, std::strong_ordering>);
-#endif
-
- return 0;
-}
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.compile.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.compile.pass.cpp
new file mode 100644
index 000000000000..69f12c9b361d
--- /dev/null
+++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.compile.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// using char_type = char16_t;
+// using int_type = uint_least16_t;
+// using off_type = streamoff;
+// using pos_type = u16streampos;
+// using state_type = mbstate_t;
+// using comparison_category = strong_ordering;
+
+#include <string>
+#include <type_traits>
+#include <cstdint>
+
+#include "test_macros.h"
+
+static_assert(std::is_same<std::char_traits<char16_t>::char_type, char16_t>::value, "");
+static_assert(std::is_same<std::char_traits<char16_t>::int_type, std::uint_least16_t>::value, "");
+static_assert(std::is_same<std::char_traits<char16_t>::off_type, std::streamoff>::value, "");
+static_assert(std::is_same<std::char_traits<char16_t>::pos_type, std::u16streampos>::value, "");
+static_assert(std::is_same<std::char_traits<char16_t>::state_type, std::mbstate_t>::value, "");
+#if TEST_STD_VER > 17
+static_assert(std::is_same_v<std::char_traits<char16_t>::comparison_category, std::strong_ordering>);
+#endif
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.pass.cpp
deleted file mode 100644
index 3dbcf2776079..000000000000
--- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.pass.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <string>
-
-// template<> struct char_traits<char16_t>
-
-// typedef char16_t char_type;
-// typedef uint_least16_t int_type;
-// typedef streamoff off_type;
-// typedef u16streampos pos_type;
-// typedef mbstate_t state_type;
-// using comparison_category = strong_ordering;
-
-#include <string>
-#include <type_traits>
-#include <cstdint>
-
-#include "test_macros.h"
-
-int main(int, char**)
-{
- static_assert((std::is_same<std::char_traits<char16_t>::char_type, char16_t>::value), "");
- static_assert((std::is_same<std::char_traits<char16_t>::int_type, std::uint_least16_t>::value), "");
- static_assert((std::is_same<std::char_traits<char16_t>::off_type, std::streamoff>::value), "");
- static_assert((std::is_same<std::char_traits<char16_t>::pos_type, std::u16streampos>::value), "");
- static_assert((std::is_same<std::char_traits<char16_t>::state_type, std::mbstate_t>::value), "");
-#if TEST_STD_VER > 17
- static_assert(std::is_same_v<std::char_traits<char16_t>::comparison_category, std::strong_ordering>);
-#endif
-
- return 0;
-}
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/types.compile.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/types.compile.pass.cpp
index aa44829f3771..2d7bcab06247 100644
--- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/types.compile.pass.cpp
+++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/types.compile.pass.cpp
@@ -10,11 +10,11 @@
// template<> struct char_traits<char32_t>
-// typedef char32_t char_type;
-// typedef uint_least32_t int_type;
-// typedef streamoff off_type;
-// typedef u32streampos pos_type;
-// typedef mbstate_t state_type;
+// using char_type = char32_t;
+// using int_type = uint_least32_t;
+// using off_type = streamoff;
+// using pos_type = u32streampos;
+// using state_type = mbstate_t;
// using comparison_category = strong_ordering;
#include <string>
@@ -23,11 +23,11 @@
#include "test_macros.h"
-static_assert((std::is_same<std::char_traits<char32_t>::char_type, char32_t>::value), "");
-static_assert((std::is_same<std::char_traits<char32_t>::int_type, std::uint_least32_t>::value), "");
-static_assert((std::is_same<std::char_traits<char32_t>::off_type, std::streamoff>::value), "");
-static_assert((std::is_same<std::char_traits<char32_t>::pos_type, std::u32streampos>::value), "");
-static_assert((std::is_same<std::char_traits<char32_t>::state_type, std::mbstate_t>::value), "");
+static_assert(std::is_same<std::char_traits<char32_t>::char_type, char32_t>::value, "");
+static_assert(std::is_same<std::char_traits<char32_t>::int_type, std::uint_least32_t>::value, "");
+static_assert(std::is_same<std::char_traits<char32_t>::off_type, std::streamoff>::value, "");
+static_assert(std::is_same<std::char_traits<char32_t>::pos_type, std::u32streampos>::value, "");
+static_assert(std::is_same<std::char_traits<char32_t>::state_type, std::mbstate_t>::value, "");
#if TEST_STD_VER > 17
static_assert(std::is_same_v<std::char_traits<char32_t>::comparison_category, std::strong_ordering>);
#endif
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.compile.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.compile.pass.cpp
new file mode 100644
index 000000000000..8dd98e85e8d7
--- /dev/null
+++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.compile.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <string>
+
+// template<> struct char_traits<char8_t>
+
+// using char_type = char8_t;
+// using int_type = unsigned int;
+// using off_type = streamoff;
+// using pos_type = u8streampos;
+// using state_type = mbstate_t;
+// using comparison_category = strong_ordering;
+
+#include <string>
+#include <type_traits>
+#include <cstdint>
+
+#include "test_macros.h"
+
+#ifndef TEST_HAS_NO_CHAR8_T
+static_assert(std::is_same<std::char_traits<char8_t>::char_type, char8_t>::value);
+static_assert(std::is_same<std::char_traits<char8_t>::int_type, unsigned int>::value);
+static_assert(std::is_same<std::char_traits<char8_t>::off_type, std::streamoff>::value);
+static_assert(std::is_same<std::char_traits<char8_t>::pos_type, std::u8streampos>::value);
+static_assert(std::is_same<std::char_traits<char8_t>::state_type, std::mbstate_t>::value);
+static_assert(std::is_same_v<std::char_traits<char8_t>::comparison_category, std::strong_ordering>);
+#endif
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.pass.cpp
deleted file mode 100644
index 51503e12f4d5..000000000000
--- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.pass.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03, c++11, c++14, c++17
-
-// <string>
-
-// template<> struct char_traits<char8_t>
-
-// typedef char8_t char_type;
-// typedef unsigned int int_type;
-// typedef streamoff off_type;
-// typedef u8streampos pos_type;
-// typedef mbstate_t state_type;
-// using comparison_category = strong_ordering;
-
-#include <string>
-#include <type_traits>
-#include <cstdint>
-
-#include "test_macros.h"
-
-int main(int, char**)
-{
-#ifndef TEST_HAS_NO_CHAR8_T
- static_assert((std::is_same<std::char_traits<char8_t>::char_type, char8_t>::value), "");
- static_assert((std::is_same<std::char_traits<char8_t>::int_type, unsigned int>::value), "");
- static_assert((std::is_same<std::char_traits<char8_t>::off_type, std::streamoff>::value), "");
- static_assert((std::is_same<std::char_traits<char8_t>::pos_type, std::u8streampos>::value), "");
- static_assert((std::is_same<std::char_traits<char8_t>::state_type, std::mbstate_t>::value), "");
- static_assert(std::is_same_v<std::char_traits<char8_t>::comparison_category, std::strong_ordering>);
-#endif
-
- return 0;
-}
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.compile.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.compile.pass.cpp
new file mode 100644
index 000000000000..9f5a701e6b0e
--- /dev/null
+++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.compile.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// using char_type = wchar_t;
+// using int_type = wint_t;
+// using off_type = streamoff;
+// using pos_type = streampos;
+// using state_type = mbstate_t;
+// using comparison_category = strong_ordering;
+
+// UNSUPPORTED: no-wide-characters
+
+#include <string>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(std::is_same<std::char_traits<wchar_t>::char_type, wchar_t>::value, "");
+static_assert(std::is_same<std::char_traits<wchar_t>::int_type, std::wint_t>::value, "");
+static_assert(std::is_same<std::char_traits<wchar_t>::off_type, std::streamoff>::value, "");
+static_assert(std::is_same<std::char_traits<wchar_t>::pos_type, std::wstreampos>::value, "");
+static_assert(std::is_same<std::char_traits<wchar_t>::state_type, std::mbstate_t>::value, "");
+#if TEST_STD_VER > 17
+static_assert(std::is_same_v<std::char_traits<wchar_t>::comparison_category, std::strong_ordering>);
+#endif
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.pass.cpp
deleted file mode 100644
index 1c932747f4a2..000000000000
--- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.pass.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <string>
-
-// template<> struct char_traits<wchar_t>
-
-// typedef wchar_t char_type;
-// typedef int int_type;
-// typedef streamoff off_type;
-// typedef streampos pos_type;
-// typedef mbstate_t state_type;
-// using comparison_category = strong_ordering;
-
-// UNSUPPORTED: no-wide-characters
-
-#include <string>
-#include <type_traits>
-
-#include "test_macros.h"
-
-int main(int, char**)
-{
- static_assert((std::is_same<std::char_traits<wchar_t>::char_type, wchar_t>::value), "");
- static_assert((std::is_same<std::char_traits<wchar_t>::int_type, std::wint_t>::value), "");
- static_assert((std::is_same<std::char_traits<wchar_t>::off_type, std::streamoff>::value), "");
- static_assert((std::is_same<std::char_traits<wchar_t>::pos_type, std::wstreampos>::value), "");
- static_assert((std::is_same<std::char_traits<wchar_t>::state_type, std::mbstate_t>::value), "");
-#if TEST_STD_VER > 17
- static_assert(std::is_same_v<std::char_traits<wchar_t>::comparison_category, std::strong_ordering>);
-#endif
-
- return 0;
-}
More information about the libcxx-commits
mailing list