Skip to content

[libc++][NFC] Replace a few "namespace std" with the correct macro #140510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2025

Conversation

philnik777
Copy link
Contributor

We've added a new macro for the unversioned namespace std cases in #133009, but it seems we've missed a few places. This fixes the places I just found.

@philnik777 philnik777 marked this pull request as ready for review May 23, 2025 20:56
@philnik777 philnik777 requested a review from a team as a code owner May 23, 2025 20:56
@philnik777 philnik777 merged commit 1d411f2 into llvm:main May 23, 2025
211 of 234 checks passed
@philnik777 philnik777 deleted the use_unversioned_namespace_macro branch May 23, 2025 20:56
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label May 23, 2025
@llvmbot
Copy link
Member

llvmbot commented May 23, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

We've added a new macro for the unversioned namespace std cases in #133009, but it seems we've missed a few places. This fixes the places I just found.


Full diff: https://github.com/llvm/llvm-project/pull/140510.diff

4 Files Affected:

  • (modified) libcxx/include/initializer_list (+4-5)
  • (modified) libcxx/include/optional (+4-3)
  • (modified) libcxx/include/stdexcept (+4-3)
  • (modified) libcxx/include/typeinfo (+4-3)
diff --git a/libcxx/include/initializer_list b/libcxx/include/initializer_list
index 00e0d4ea4a2df..b66b734eb57f9 100644
--- a/libcxx/include/initializer_list
+++ b/libcxx/include/initializer_list
@@ -53,11 +53,10 @@ template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in
 #    pragma GCC system_header
 #  endif
 
-namespace std // purposefully not versioned
-{
-
 #  ifndef _LIBCPP_CXX03_LANG
 
+_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
+
 template <class _Ep>
 class _LIBCPP_NO_SPECIALIZATIONS initializer_list {
   const _Ep* __begin_;
@@ -95,9 +94,9 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* end(initia
   return __il.end();
 }
 
-#  endif // !defined(_LIBCPP_CXX03_LANG)
+_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
 
-} // namespace std
+#  endif // !defined(_LIBCPP_CXX03_LANG)
 
 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
 #    include <cstddef>
diff --git a/libcxx/include/optional b/libcxx/include/optional
index 2153efb2ab899..b60ddb91ce5d6 100644
--- a/libcxx/include/optional
+++ b/libcxx/include/optional
@@ -244,8 +244,8 @@ namespace std {
 _LIBCPP_PUSH_MACROS
 #  include <__undef_macros>
 
-namespace std // purposefully not using versioning namespace
-{
+_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
+_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
 
 class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access : public exception {
 public:
@@ -257,7 +257,8 @@ public:
   const char* what() const _NOEXCEPT override;
 };
 
-} // namespace std
+_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
+_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
 
 #  if _LIBCPP_STD_VER >= 17
 
diff --git a/libcxx/include/stdexcept b/libcxx/include/stdexcept
index 610b409132543..a2116c133ade3 100644
--- a/libcxx/include/stdexcept
+++ b/libcxx/include/stdexcept
@@ -73,8 +73,8 @@ public:
 
 _LIBCPP_END_NAMESPACE_STD
 
-namespace std // purposefully not using versioning namespace
-{
+_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
+_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
 
 class _LIBCPP_EXPORTED_FROM_ABI logic_error : public exception {
 #  ifndef _LIBCPP_ABI_VCRUNTIME
@@ -207,7 +207,8 @@ public:
 #  endif
 };
 
-} // namespace std
+_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
+_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
diff --git a/libcxx/include/typeinfo b/libcxx/include/typeinfo
index 24aaabf0a87df..1f056d2e66bde 100644
--- a/libcxx/include/typeinfo
+++ b/libcxx/include/typeinfo
@@ -76,8 +76,8 @@ public:
 #    include <vcruntime_typeinfo.h>
 #  else
 
-namespace std // purposefully not using versioning namespace
-{
+_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
+_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
 
 #    if defined(_LIBCPP_ABI_MICROSOFT)
 
@@ -348,7 +348,8 @@ public:
   const char* what() const _NOEXCEPT override;
 };
 
-} // namespace std
+_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
+_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
 
 #  endif // defined(_LIBCPP_ABI_VCRUNTIME)
 

jyknight added a commit to jyknight/llvm-project that referenced this pull request May 28, 2025
jyknight added a commit that referenced this pull request May 28, 2025
…BCPP_HIDE_FROM_ABI everywhere (#131156)" (#141756)

This reverts commit c861fe8.

Unfortunately, this use of hidden visibility attributes causes
user-defined specializations of standard-library types to also be marked
hidden by default, which is incorrect. See discussion thread on #131156.

...and also reverts the follow-up commits:

Revert "[libc++] Add explicit ABI annotations to functions from the block runtime declared in <__functional/function.h> (#140592)"
This reverts commit 3e4c9dc.

Revert "[libc++] Make ABI annotations explicit for windows-specific code (#140507)"
This reverts commit f73287e.

Revert "[libc++][NFC] Replace a few "namespace std" with the correct macro (#140510)"
This reverts commit 1d411f2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants