[libcxx-commits] [libcxx] [libc++] Add test to ensure that the mangling of types stays the same (PR #143556)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 18 08:56:20 PDT 2025


================
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// We're using `std::from_chars` in this test
+// UNSUPPORTED: c++03, c++11, c++14
+
+// Make sure that the mangling of our public types stays the same
+
+#include <cassert>
+#include <charconv>
+#include <iostream>
+#include <map>
+#include <typeinfo>
+#include <string_view>
+
+template <class>
+struct mangling {};
+
+struct test_struct {};
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+struct ns_mangling {};
+_LIBCPP_END_NAMESPACE_STD
+
+namespace std::__name {
+struct ns_mangling {};
+} // namespace std::__name
+
+namespace std::__long_name_to_make_sure_multiple_digits_work {
+struct ns_mangling {};
+} // namespace std::__long_name_to_make_sure_multiple_digits_work
+
+std::string get_std_inline_namespace_mangling(const std::type_info& info) {
+  std::string name = info.name();
+  assert(name.starts_with("NSt"));
+  unsigned name_len;
+  auto res = std::from_chars(name.data() + 3, name.data() + name.size(), name_len);
+  assert(res.ec == std::errc{});
+  return std::move(name).substr(0, (res.ptr + name_len) - name.data());
+}
+
+void expect_mangling(const std::type_info& info, std::string expected_name) {
+  if (expected_name != info.name())
+    std::__libcpp_verbose_abort("Expected: '%s'\n     Got: '%s'\n", expected_name.c_str(), info.name());
+}
+
+#define EXPECT_MANGLING(expected_mangling, ...) expect_mangling(typeid(__VA_ARGS__), expected_mangling)
----------------
ldionne wrote:

I'm not sure the macro buys us a lot.

https://github.com/llvm/llvm-project/pull/143556


More information about the libcxx-commits mailing list