[libcxx-commits] [libcxx] [libc++] Fix the visibility of type traits (PR #111522)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 9 12:46:33 PDT 2024


================
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// Make sure that the types and variables have the correct visibility attributes
+
+// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -DSHARED -fPIC -fvisibility=hidden -shared -o %t.shared_lib
+// RUN: %{build} -fvisibility=hidden %t.shared_lib
+// RUN: %{run}
+
+#include <algorithm>
+#include <cassert>
+#include <type_traits>
+#include <vector>
+
+[[gnu::visibility("default")]] extern std::vector<const std::type_info*> shared_lib_type_infos;
+
+struct [[gnu::visibility("default")]] S {
+  static constexpr bool value = false;
+};
+
+inline std::vector<const std::type_info*> get_type_infos() {
+  return {
+      &typeid(std::remove_const<int>),
----------------
philnik777 wrote:

I agree that type traits aren't the most useful to have correct RTTI for. I really just started with those because I had to write a test for the variables anyways. Adding a test for the classes was not significantly more work than copy-pasting the code. OTOH I could see a use-case for pretty much every non-empty type, so adding the few empty types doesn't seem like that much extra work for a tick-mark in "fully conforming across dylib boundaries".

I think it would be good to add tests for the important types (`string`, `vector`, exception types, etc.), since I did almost regress on this a few times in the past. Then again, the situation has changed now, since all types are properly annotated through `_LIBCPP_BEGIN_NAMESPACE_STD` except when using GCC. So maybe it would be good enough to add a clang-tidy test ensuring all public types have the proper annotations.

FYI we'll probably have a longer discussion on GCC and ABI guarantees tomorrow, so maybe we could talk about this more at that point if there is some time.


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


More information about the libcxx-commits mailing list