Skip to content

[libc++] Qualify calls to nullary functions like __throw_foo #122465

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 9 commits into from
Feb 21, 2025

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Jan 10, 2025

This is technically not necessary in most cases to prevent issues with ADL, but let's be consistent.
This allows us to remove the libcpp-qualify-declval clang-tidy check, which is now enforced by
the robust-against-adl clang-tidy check.

@ldionne ldionne requested a review from a team as a code owner January 10, 2025 14:43
@ldionne ldionne changed the title [libc++] Qualify calls to __throw_foo & friends [libc++] Qualify calls to __throw_foo Jan 10, 2025
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 10, 2025

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

This is technically not necessary in most cases to prevent issues with ADL, but let's be consistent.


Patch is 110.36 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/122465.diff

41 Files Affected:

  • (modified) libcxx/include/__condition_variable/condition_variable.h (+2-2)
  • (modified) libcxx/include/__filesystem/directory_entry.h (+1-1)
  • (modified) libcxx/include/__functional/function.h (+2-2)
  • (modified) libcxx/include/__locale (+5-5)
  • (modified) libcxx/include/__locale_dir/support/windows.h (+2-2)
  • (modified) libcxx/include/__memory/allocator.h (+1-1)
  • (modified) libcxx/include/__memory/shared_ptr.h (+1-1)
  • (modified) libcxx/include/__memory_resource/polymorphic_allocator.h (+1-1)
  • (modified) libcxx/include/__mutex/unique_lock.h (+9-9)
  • (modified) libcxx/include/__ostream/basic_ostream.h (+1-1)
  • (modified) libcxx/include/__thread/thread.h (+3-3)
  • (modified) libcxx/include/__vector/vector.h (+1-1)
  • (modified) libcxx/include/__vector/vector_bool.h (+1-1)
  • (modified) libcxx/include/any (+3-3)
  • (modified) libcxx/include/array (+4-4)
  • (modified) libcxx/include/bitset (+7-7)
  • (modified) libcxx/include/fstream (+4-4)
  • (modified) libcxx/include/future (+27-27)
  • (modified) libcxx/include/locale (+12-12)
  • (modified) libcxx/include/map (+2-2)
  • (modified) libcxx/include/optional (+4-4)
  • (modified) libcxx/include/regex (+65-65)
  • (modified) libcxx/include/shared_mutex (+9-9)
  • (modified) libcxx/include/string (+29-29)
  • (modified) libcxx/include/string_view (+1-1)
  • (modified) libcxx/include/unordered_map (+2-2)
  • (modified) libcxx/include/variant (+2-2)
  • (modified) libcxx/src/chrono.cpp (+6-6)
  • (modified) libcxx/src/condition_variable.cpp (+4-4)
  • (modified) libcxx/src/filesystem/error.h (+6-6)
  • (modified) libcxx/src/filesystem/filesystem_clock.cpp (+2-2)
  • (modified) libcxx/src/future.cpp (+10-10)
  • (modified) libcxx/src/hash.cpp (+2-2)
  • (modified) libcxx/src/ios.cpp (+5-5)
  • (modified) libcxx/src/locale.cpp (+34-34)
  • (modified) libcxx/src/memory_resource.cpp (+2-2)
  • (modified) libcxx/src/mutex.cpp (+4-4)
  • (modified) libcxx/src/print.cpp (+1-1)
  • (modified) libcxx/src/random.cpp (+12-12)
  • (modified) libcxx/src/std_stream.h (+1-1)
  • (modified) libcxx/src/thread.cpp (+2-2)
diff --git a/libcxx/include/__condition_variable/condition_variable.h b/libcxx/include/__condition_variable/condition_variable.h
index 4521fe274614ef..82ecb804669e65 100644
--- a/libcxx/include/__condition_variable/condition_variable.h
+++ b/libcxx/include/__condition_variable/condition_variable.h
@@ -210,7 +210,7 @@ inline void condition_variable::__do_timed_wait(
     unique_lock<mutex>& __lk, chrono::time_point<chrono::steady_clock, chrono::nanoseconds> __tp) _NOEXCEPT {
   using namespace chrono;
   if (!__lk.owns_lock())
-    __throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked");
+    std::__throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked");
   nanoseconds __d = __tp.time_since_epoch();
   timespec __ts;
   seconds __s                 = duration_cast<seconds>(__d);
@@ -225,7 +225,7 @@ inline void condition_variable::__do_timed_wait(
   }
   int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts);
   if (__ec != 0 && __ec != ETIMEDOUT)
-    __throw_system_error(__ec, "condition_variable timed_wait failed");
+    std::__throw_system_error(__ec, "condition_variable timed_wait failed");
 }
 #  endif // _LIBCPP_HAS_COND_CLOCKWAIT
 
diff --git a/libcxx/include/__filesystem/directory_entry.h b/libcxx/include/__filesystem/directory_entry.h
index 11e07acdbe00c7..5f236cf2648df6 100644
--- a/libcxx/include/__filesystem/directory_entry.h
+++ b/libcxx/include/__filesystem/directory_entry.h
@@ -286,7 +286,7 @@ class directory_entry {
       return;
     }
     if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
-      __throw_filesystem_error(__msg, __p_, __ec);
+      filesystem::__throw_filesystem_error(__msg, __p_, __ec);
   }
 
   _LIBCPP_HIDE_FROM_ABI void __refresh(error_code* __ec = nullptr) {
diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h
index b483e8ea8f8567..e6300ba7dd8cbb 100644
--- a/libcxx/include/__functional/function.h
+++ b/libcxx/include/__functional/function.h
@@ -427,7 +427,7 @@ class __value_func<_Rp(_ArgTypes...)> {
 
   _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __args) const {
     if (__f_ == nullptr)
-      __throw_bad_function_call();
+      std::__throw_bad_function_call();
     return (*__f_)(std::forward<_ArgTypes>(__args)...);
   }
 
@@ -602,7 +602,7 @@ struct __policy_invoker<_Rp(_ArgTypes...)> {
   _LIBCPP_HIDE_FROM_ABI explicit __policy_invoker(__Call __c) : __call_(__c) {}
 
   _LIBCPP_HIDE_FROM_ABI static _Rp __call_empty(const __policy_storage*, __fast_forward<_ArgTypes>...) {
-    __throw_bad_function_call();
+    std::__throw_bad_function_call();
   }
 
   template <typename _Fun>
diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index 94dc8a08437bfe..e7bfbbdd636436 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -153,7 +153,7 @@ inline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* __f)
 template <class _Facet>
 locale locale::combine(const locale& __other) const {
   if (!std::has_facet<_Facet>(__other))
-    __throw_runtime_error("locale::combine: locale missing facet");
+    std::__throw_runtime_error("locale::combine: locale missing facet");
 
   return locale(*this, &const_cast<_Facet&>(std::use_facet<_Facet>(__other)));
 }
@@ -1295,7 +1295,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16> : public codecvt<char16_t,
       const char16_t* __wn = (const char16_t*)__wb;
       __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, __buf, __buf + __sz, __bn);
       if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
-        __throw_runtime_error("locale not supported");
+        std::__throw_runtime_error("locale not supported");
       for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
         *__s = *__p;
       __wb = (const _CharT*)__wn;
@@ -1323,7 +1323,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32> : public codecvt<char32_t,
       const char32_t* __wn = (const char32_t*)__wb;
       __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, __buf, __buf + __sz, __bn);
       if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
-        __throw_runtime_error("locale not supported");
+        std::__throw_runtime_error("locale not supported");
       for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
         *__s = *__p;
       __wb = (const _CharT*)__wn;
@@ -1367,7 +1367,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16> : public codecvt<char16_t
       const char* __nn = __nb;
       __r              = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);
       if (__r == codecvt_base::error || __nn == __nb)
-        __throw_runtime_error("locale not supported");
+        std::__throw_runtime_error("locale not supported");
       for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
         *__s = *__p;
       __nb = __nn;
@@ -1395,7 +1395,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32> : public codecvt<char32_t
       const char* __nn = __nb;
       __r              = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);
       if (__r == codecvt_base::error || __nn == __nb)
-        __throw_runtime_error("locale not supported");
+        std::__throw_runtime_error("locale not supported");
       for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
         *__s = *__p;
       __nb = __nn;
diff --git a/libcxx/include/__locale_dir/support/windows.h b/libcxx/include/__locale_dir/support/windows.h
index eca0e17d94c85a..60376867cc202c 100644
--- a/libcxx/include/__locale_dir/support/windows.h
+++ b/libcxx/include/__locale_dir/support/windows.h
@@ -300,7 +300,7 @@ struct __locale_guard {
     if (std::strcmp(__l.__get_locale(), __lc) != 0) {
       __locale_all = _strdup(__lc);
       if (__locale_all == nullptr)
-        __throw_bad_alloc();
+        std::__throw_bad_alloc();
       __setlocale(__l.__get_locale());
     }
   }
@@ -318,7 +318,7 @@ struct __locale_guard {
   _LIBCPP_HIDE_FROM_ABI static const char* __setlocale(const char* __locale) {
     const char* __new_locale = setlocale(LC_ALL, __locale);
     if (__new_locale == nullptr)
-      __throw_bad_alloc();
+      std::__throw_bad_alloc();
     return __new_locale;
   }
   int __status;
diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index a7066885a978a6..b499bef80b51d4 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -98,7 +98,7 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::v
   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* allocate(size_t __n) {
     static_assert(sizeof(_Tp) >= 0, "cannot allocate memory for an incomplete type");
     if (__n > allocator_traits<allocator>::max_size(*this))
-      __throw_bad_array_new_length();
+      std::__throw_bad_array_new_length();
     if (__libcpp_is_constant_evaluated()) {
       return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
     } else {
diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index 06b1fc488cf515..cc43ca1cbe189e 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -496,7 +496,7 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
   _LIBCPP_HIDE_FROM_ABI explicit shared_ptr(const weak_ptr<_Yp>& __r)
       : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) {
     if (__cntrl_ == nullptr)
-      __throw_bad_weak_ptr();
+      std::__throw_bad_weak_ptr();
   }
 
 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h
index 2dec9788852c2b..7e7eca5c64fb61 100644
--- a/libcxx/include/__memory_resource/polymorphic_allocator.h
+++ b/libcxx/include/__memory_resource/polymorphic_allocator.h
@@ -64,7 +64,7 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_TEMPLATE_VIS polymorphic_allocator {
 
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _ValueType* allocate(size_t __n) {
     if (__n > __max_size()) {
-      __throw_bad_array_new_length();
+      std::__throw_bad_array_new_length();
     }
     return static_cast<_ValueType*>(__res_->allocate(__n * sizeof(_ValueType), alignof(_ValueType)));
   }
diff --git a/libcxx/include/__mutex/unique_lock.h b/libcxx/include/__mutex/unique_lock.h
index 3642ab93cb1f7c..84073ef4b5114a 100644
--- a/libcxx/include/__mutex/unique_lock.h
+++ b/libcxx/include/__mutex/unique_lock.h
@@ -116,9 +116,9 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(unique_lock);
 template <class _Mutex>
 _LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::lock() {
   if (__m_ == nullptr)
-    __throw_system_error(EPERM, "unique_lock::lock: references null mutex");
+    std::__throw_system_error(EPERM, "unique_lock::lock: references null mutex");
   if (__owns_)
-    __throw_system_error(EDEADLK, "unique_lock::lock: already locked");
+    std::__throw_system_error(EDEADLK, "unique_lock::lock: already locked");
   __m_->lock();
   __owns_ = true;
 }
@@ -126,9 +126,9 @@ _LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::lock() {
 template <class _Mutex>
 _LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock() {
   if (__m_ == nullptr)
-    __throw_system_error(EPERM, "unique_lock::try_lock: references null mutex");
+    std::__throw_system_error(EPERM, "unique_lock::try_lock: references null mutex");
   if (__owns_)
-    __throw_system_error(EDEADLK, "unique_lock::try_lock: already locked");
+    std::__throw_system_error(EDEADLK, "unique_lock::try_lock: already locked");
   __owns_ = __m_->try_lock();
   return __owns_;
 }
@@ -137,9 +137,9 @@ template <class _Mutex>
 template <class _Rep, class _Period>
 _LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
   if (__m_ == nullptr)
-    __throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex");
+    std::__throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex");
   if (__owns_)
-    __throw_system_error(EDEADLK, "unique_lock::try_lock_for: already locked");
+    std::__throw_system_error(EDEADLK, "unique_lock::try_lock_for: already locked");
   __owns_ = __m_->try_lock_for(__d);
   return __owns_;
 }
@@ -148,9 +148,9 @@ template <class _Mutex>
 template <class _Clock, class _Duration>
 _LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
   if (__m_ == nullptr)
-    __throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex");
+    std::__throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex");
   if (__owns_)
-    __throw_system_error(EDEADLK, "unique_lock::try_lock_until: already locked");
+    std::__throw_system_error(EDEADLK, "unique_lock::try_lock_until: already locked");
   __owns_ = __m_->try_lock_until(__t);
   return __owns_;
 }
@@ -158,7 +158,7 @@ _LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock_until(const chrono::tim
 template <class _Mutex>
 _LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::unlock() {
   if (!__owns_)
-    __throw_system_error(EPERM, "unique_lock::unlock: not locked");
+    std::__throw_system_error(EPERM, "unique_lock::unlock: not locked");
   __m_->unlock();
   __owns_ = false;
 }
diff --git a/libcxx/include/__ostream/basic_ostream.h b/libcxx/include/__ostream/basic_ostream.h
index 97226476e5ef0d..06bf54a5bd2f6b 100644
--- a/libcxx/include/__ostream/basic_ostream.h
+++ b/libcxx/include/__ostream/basic_ostream.h
@@ -407,7 +407,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) {
       if (__len > __bs) {
         __wb = (_CharT*)malloc(__len * sizeof(_CharT));
         if (__wb == 0)
-          __throw_bad_alloc();
+          std::__throw_bad_alloc();
         __h.reset(__wb);
       }
       for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
diff --git a/libcxx/include/__thread/thread.h b/libcxx/include/__thread/thread.h
index c40ffd25b903c2..8e5b97f2a5c008 100644
--- a/libcxx/include/__thread/thread.h
+++ b/libcxx/include/__thread/thread.h
@@ -100,7 +100,7 @@ template <class _Tp>
 __thread_specific_ptr<_Tp>::__thread_specific_ptr() {
   int __ec = __libcpp_tls_create(&__key_, &__thread_specific_ptr::__at_thread_exit);
   if (__ec)
-    __throw_system_error(__ec, "__thread_specific_ptr construction failed");
+    std::__throw_system_error(__ec, "__thread_specific_ptr construction failed");
 }
 
 template <class _Tp>
@@ -219,7 +219,7 @@ thread::thread(_Fp&& __f, _Args&&... __args) {
   if (__ec == 0)
     __p.release();
   else
-    __throw_system_error(__ec, "thread constructor failed");
+    std::__throw_system_error(__ec, "thread constructor failed");
 }
 
 #  else // _LIBCPP_CXX03_LANG
@@ -251,7 +251,7 @@ thread::thread(_Fp __f) {
   if (__ec == 0)
     __pp.release();
   else
-    __throw_system_error(__ec, "thread constructor failed");
+    std::__throw_system_error(__ec, "thread constructor failed");
 }
 
 #  endif // _LIBCPP_CXX03_LANG
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index ddbf1235b90691..421b32291c3c6f 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -550,7 +550,7 @@ class _LIBCPP_TEMPLATE_VIS vector {
   //  Postcondition:  size() == 0
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
     if (__n > max_size())
-      __throw_length_error();
+      this->__throw_length_error();
     auto __allocation = std::__allocate_at_least(this->__alloc_, __n);
     __begin_          = __allocation.ptr;
     __end_            = __allocation.ptr;
diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index 2b721e00058bc6..5da1b547c3952d 100644
--- a/libcxx/include/__vector/vector_bool.h
+++ b/libcxx/include/__vector/vector_bool.h
@@ -441,7 +441,7 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
   //  Postcondition:  size() == 0
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) {
     if (__n > max_size())
-      __throw_length_error();
+      this->__throw_length_error();
     auto __allocation = std::__allocate_at_least(__alloc_, __external_cap_to_internal(__n));
     __begin_          = __allocation.ptr;
     __size_           = 0;
diff --git a/libcxx/include/any b/libcxx/include/any
index 786e86b5ccd8b3..b1df494d3db83f 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -526,7 +526,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType
                 "or a CopyConstructible type");
   auto __tmp = std::any_cast<add_const_t<_RawValueType>>(&__v);
   if (__tmp == nullptr)
-    __throw_bad_any_cast();
+    std::__throw_bad_any_cast();
   return static_cast<_ValueType>(*__tmp);
 }
 
@@ -538,7 +538,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType
                 "or a CopyConstructible type");
   auto __tmp = std::any_cast<_RawValueType>(&__v);
   if (__tmp == nullptr)
-    __throw_bad_any_cast();
+    std::__throw_bad_any_cast();
   return static_cast<_ValueType>(*__tmp);
 }
 
@@ -550,7 +550,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType
                 "or a CopyConstructible type");
   auto __tmp = std::any_cast<_RawValueType>(&__v);
   if (__tmp == nullptr)
-    __throw_bad_any_cast();
+    std::__throw_bad_any_cast();
   return static_cast<_ValueType>(std::move(*__tmp));
 }
 
diff --git a/libcxx/include/array b/libcxx/include/array
index 1b9bcd6891d952..44c6bb5c5cc933 100644
--- a/libcxx/include/array
+++ b/libcxx/include/array
@@ -276,13 +276,13 @@ struct _LIBCPP_TEMPLATE_VIS array {
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n) {
     if (__n >= _Size)
-      __throw_out_of_range("array::at");
+      std::__throw_out_of_range("array::at");
     return __elems_[__n];
   }
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const {
     if (__n >= _Size)
-      __throw_out_of_range("array::at");
+      std::__throw_out_of_range("array::at");
     return __elems_[__n];
   }
 
@@ -407,12 +407,12 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
   }
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type) {
-    __throw_out_of_range("array<T, 0>::at");
+    std::__throw_out_of_range("array<T, 0>::at");
     __libcpp_unreachable();
   }
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type) const {
-    __throw_out_of_range("array<T, 0>::at");
+    std::__throw_out_of_range("array<T, 0>::at");
     __libcpp_unreachable();
   }
 
diff --git a/libcxx/include/bitset b/libcxx/include/bitset
index c16635dc8092cd..58f5ac89119999 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -341,7 +341,7 @@ __bitset<_N_words, _Size>::to_ulong(false_type) const {
   __const_iterator __e = __make_iter(_Size);
   __const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
   if (__i != __e)
-    __throw_overflow_error("bitset to_ulong overflow error");
+    std::__throw_overflow_error("bitset to_ulong overflow error");
 
   return __first_[0];
 }
@@ -358,7 +358,7 @@ __bitset<_N_words, _Size>::to_ullong(false_type) const {
   __const_iterator __e = __make_iter(_Size);
   __const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
   if (__i != __e)
-    __throw_overflow_error("bitset to_ullong overflow error");
+    std::__throw_overflow_error("bitset to_ullong overflow error");
 
   return to_ullong(true_type());
 }
@@ -647,7 +647,7 @@ public:
       _CharT __zero                                                = _CharT('0'),
       _CharT __one                                                 = _CharT('1')) {
     if (__pos > __str.size())
-      __throw_out_of_range("bitset string pos out of range");
+      std::__throw_out_of_range("bitset string pos out of range");
 
     size_t __rlen = std::min(__n, __str.size() - __pos);
     __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
@@ -792,7 +792,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset
 template <size_t _Size>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) {
   if (__pos >= _Size)
-    __throw_out_of_range("bitset set argument out of range");
+    std::__throw_out_of_range("bitset set argument out of range");
 
   (*this)[__pos] = __val;
   return *this;
@@ -807,7 +807,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset
 template <size_t _Size>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) {
   if (__pos >= _Size)
-    __throw_out_of_range("bitset reset argument out of range");
+    std::__throw_out_of_range("bitset reset argument out of range");
 
   (*this)[__pos] = false;
   return *this;
@@ -829,7 +829,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset
 template <size_t _Size>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) {
   if (__pos >= _Size)
-    __throw_out_of_range("bitset flip argument out of range");
+    std::__throw_out_of_range("bitset flip argument out of range");
 
   reference __r = __base::__make_ref(__pos);
   __r           = ~__r;
@@ -901,7 +901,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs)
 template <size_t _Size>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const {
   if (__pos >= _Size)
-    __throw_out_of_range("bitset test argument out of range");
+    std::__throw_out_of_range("bitset test argument out of range");
 
   return (*this)[__pos];
 }
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index f0e9425e0a53d9..ec94789306f277 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -783,7 +783,7 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT,...
[truncated]

@ldionne ldionne force-pushed the review/qualify-throw-xxx branch from 9bcf239 to 1516a39 Compare January 13, 2025 20:24
Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the unless(argumentCountIs(0)) from robust_against_adl.cpp and fix any issues? That would remove the need for libcpp-qualify-declval entirely I think.

@mordante
Copy link
Member

Should we remove the unless(argumentCountIs(0)) from robust_against_adl.cpp and fix any issues? That would remove the need for libcpp-qualify-declval entirely I think.

I like that idea! This makes it consistent.

This is technically not necessary in most cases to prevent issues with
ADL, but let's be consistent.
@ldionne ldionne force-pushed the review/qualify-throw-xxx branch from 1516a39 to 42cd114 Compare February 18, 2025 20:16
@ldionne ldionne changed the title [libc++] Qualify calls to __throw_foo [libc++] Qualify calls to nullary functions like __throw_foo Feb 18, 2025
Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming the CI is happy.

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this. I'm very happy we can now detect these with clang-tidy!

@ldionne ldionne added the pending-ci Merging the PR is only pending completion of CI label Feb 20, 2025
@ldionne ldionne merged commit 5e26fb1 into llvm:main Feb 21, 2025
78 checks passed
@ldionne ldionne deleted the review/qualify-throw-xxx branch February 21, 2025 12:59
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. pending-ci Merging the PR is only pending completion of CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants