[libcxx-commits] [PATCH] D116120: [libc++][format] Improve ABI stability.
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 22 08:51:32 PST 2021
Mordante updated this revision to Diff 395884.
Mordante added a comment.
Addresses review comments and fixes CI.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116120/new/
https://reviews.llvm.org/D116120
Files:
libcxx/include/__format/format_arg.h
libcxx/test/libcxx/utilities/format/format.arguments/format.arg/arg_t.compile.pass.cpp
Index: libcxx/test/libcxx/utilities/format/format.arguments/format.arg/arg_t.compile.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/libcxx/utilities/format/format.arguments/format.arg/arg_t.compile.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+// 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
+// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: libcpp-has-no-incomplete-format
+
+// <format>
+
+// namespace __format { enum class __arg_t : uint8_t{...}; }
+
+#include <format>
+
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(std::is_same_v<std::underlying_type_t<std::__format::__arg_t>, uint8_t>);
+
+static_assert(uint8_t(std::__format::__arg_t::__none) == 0);
+static_assert(uint8_t(std::__format::__arg_t::__boolean) == 1);
+static_assert(uint8_t(std::__format::__arg_t::__char_type) == 2);
+static_assert(uint8_t(std::__format::__arg_t::__int) == 3);
+static_assert(uint8_t(std::__format::__arg_t::__long_long) == 4);
+static_assert(uint8_t(std::__format::__arg_t::__i128) == 5);
+static_assert(uint8_t(std::__format::__arg_t::__unsigned) == 6);
+static_assert(uint8_t(std::__format::__arg_t::__unsigned_long_long) == 7);
+static_assert(uint8_t(std::__format::__arg_t::__u128) == 8);
+static_assert(uint8_t(std::__format::__arg_t::__float) == 9);
+static_assert(uint8_t(std::__format::__arg_t::__double) == 10);
+static_assert(uint8_t(std::__format::__arg_t::__long_double) == 11);
+static_assert(uint8_t(std::__format::__arg_t::__const_char_type_ptr) == 12);
+static_assert(uint8_t(std::__format::__arg_t::__string_view) == 13);
+static_assert(uint8_t(std::__format::__arg_t::__ptr) == 14);
Index: libcxx/include/__format/format_arg.h
===================================================================
--- libcxx/include/__format/format_arg.h
+++ libcxx/include/__format/format_arg.h
@@ -37,21 +37,20 @@
#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
namespace __format {
-/** The type stored in @ref basic_format_arg. */
+/// The type stored in @ref basic_format_arg.
+///
+/// @note The 128-bit types are unconditionally in the list to avoid the values
+/// of the enums to depend on the availability of 128-bit integers.
enum class _LIBCPP_ENUM_VIS __arg_t : uint8_t {
__none,
__boolean,
__char_type,
__int,
__long_long,
-#ifndef _LIBCPP_HAS_NO_INT128
__i128,
-#endif
__unsigned,
__unsigned_long_long,
-#ifndef _LIBCPP_HAS_NO_INT128
__u128,
-#endif
__float,
__double,
__long_double,
@@ -75,18 +74,22 @@
return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__int);
case __format::__arg_t::__long_long:
return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__long_long);
-#ifndef _LIBCPP_HAS_NO_INT128
case __format::__arg_t::__i128:
+#ifndef _LIBCPP_HAS_NO_INT128
return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__i128);
+#else
+ _LIBCPP_UNREACHABLE();
#endif
case __format::__arg_t::__unsigned:
return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__unsigned);
case __format::__arg_t::__unsigned_long_long:
return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis),
__arg.__unsigned_long_long);
-#ifndef _LIBCPP_HAS_NO_INT128
case __format::__arg_t::__u128:
+#ifndef _LIBCPP_HAS_NO_INT128
return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__u128);
+#else
+ _LIBCPP_UNREACHABLE();
#endif
case __format::__arg_t::__float:
return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__float);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116120.395884.patch
Type: text/x-patch
Size: 3888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211222/1e23529e/attachment.bin>
More information about the libcxx-commits
mailing list