[libcxx-commits] [libcxx] [libc++] Fix the visibility of type traits (PR #111522)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 9 12:30:17 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>),
----------------
ldionne wrote:
This has the potential to get really out of hands for a questionable benefit, don't you think? Some types definitely need their visibility to be correct, like exception types. If we make a mistake on one of those, the exception handling mechanism won't work properly. But for e.g. type traits, this really doesn't matter that much. I think that's why I'm surprised you're starting with those tests.
If we follow the reasoning here, we would end up adding a test that every type we add to the library has the right visibility. And we would add a new test like that whenever we implement a new user-visible type. Is that what you have in mind?
https://github.com/llvm/llvm-project/pull/111522
More information about the libcxx-commits
mailing list