[libcxx-commits] [PATCH] D134031: [libc++][test] Adds format string helper.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 16 06:01:29 PDT 2022


Mordante created this revision.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134031

Files:
  libcxx/test/support/test_format_string.h


Index: libcxx/test/support/test_format_string.h
===================================================================
--- /dev/null
+++ libcxx/test/support/test_format_string.h
@@ -0,0 +1,42 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SUPPORT_TEST_FORMAT_STRING_HPP
+#define SUPPORT_TEST_FORMAT_STRING_HPP
+
+#include <format>
+#include <type_traits>
+
+#include "test_macros.h"
+
+#if TEST_STD_VER < 20
+#  error "The format header requires at least C++20"
+#endif
+
+// Wrapper for basic_format_string.
+//
+// This layer of indirection is used since it's not possible to use
+// std::basic_format_string<CharT, Args...> in the test function directly.
+//
+// In C++20 the basic-format-string was an exposition only type. In C++23 is
+// has been replaced with basic_format_string. Both libc++ and MSVC STL offer
+// it as an extension in C++20.
+#if TEST_STD_VER > 20 || defined(_LIBCPP_VERSION) || defined(_MSVC_STL_VERSION)
+template <class CharT, class... Args>
+using test_format_string =
+    std::conditional_t<std::same_as<CharT, char>, std::format_string<Args...>, std::wformat_string<Args...>>;
+
+#else // TEST_STD_VER > 20 || defined(_LIBCPP_VERSION) || defined( _MSVC_STL_VERSION)
+
+#  error
+"Please create a vendor specific version of the test typedef and file a review at https://reviews.llvm.org/"
+
+#endif // TEST_STD_VER > 20 || defined(_LIBCPP_VERSION) || defined( _MSVC_STL_VERSION)
+
+#endif // SUPPORT_TEST_FORMAT_STRING_HPP


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134031.460712.patch
Type: text/x-patch
Size: 1812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220916/e991025e/attachment-0001.bin>


More information about the libcxx-commits mailing list