[libcxx-commits] [libcxx] [libc++] re-enable clang-tidy in the CI and fix any issues (PR #102658)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Aug 10 01:08:34 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

<details>
<summary>Changes</summary>

It looks like we've accidentally disabled clang-tidy in the CI. This re-enables it and fixes the issues accumulated while it was disabled.


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


11 Files Affected:

- (modified) libcxx/include/__atomic/atomic_ref.h (+1-1) 
- (modified) libcxx/include/__bit/rotate.h (+8-8) 
- (modified) libcxx/include/__chrono/zoned_time.h (+2-2) 
- (modified) libcxx/include/__format/format_context.h (+1) 
- (modified) libcxx/include/__memory_resource/polymorphic_allocator.h (+4-2) 
- (modified) libcxx/include/__mutex/unique_lock.h (+10-10) 
- (modified) libcxx/include/memory_resource (-1) 
- (modified) libcxx/modules/std/mdspan.inc (+5) 
- (modified) libcxx/modules/std/new.inc (+4-2) 
- (modified) libcxx/test/tools/clang_tidy_checks/CMakeLists.txt (+2-2) 
- (modified) libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp (+4-2) 


``````````diff
diff --git a/libcxx/include/__atomic/atomic_ref.h b/libcxx/include/__atomic/atomic_ref.h
index b0180a37ab500c..92e9247e2e50eb 100644
--- a/libcxx/include/__atomic/atomic_ref.h
+++ b/libcxx/include/__atomic/atomic_ref.h
@@ -219,7 +219,7 @@ struct __atomic_ref_base {
   _LIBCPP_HIDE_FROM_ABI void notify_all() const noexcept { std::__atomic_notify_all(*this); }
 
 protected:
-  typedef _Tp _Aligned_Tp __attribute__((aligned(required_alignment)));
+  using _Aligned_Tp [[__gnu__::__aligned__(required_alignment)]] = _Tp;
   _Aligned_Tp* __ptr_;
 
   _LIBCPP_HIDE_FROM_ABI __atomic_ref_base(_Tp& __obj) : __ptr_(std::addressof(__obj)) {}
diff --git a/libcxx/include/__bit/rotate.h b/libcxx/include/__bit/rotate.h
index 90e430e9d04256..d79d98de296aaf 100644
--- a/libcxx/include/__bit/rotate.h
+++ b/libcxx/include/__bit/rotate.h
@@ -26,31 +26,31 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 template <class _Tp>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotl(_Tp __x, int __s) _NOEXCEPT {
   static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotl requires an unsigned integer type");
-  const int __N = numeric_limits<_Tp>::digits;
-  int __r       = __s % __N;
+  const int __n = numeric_limits<_Tp>::digits;
+  int __r       = __s % __n;
 
   if (__r == 0)
     return __x;
 
   if (__r > 0)
-    return (__x << __r) | (__x >> (__N - __r));
+    return (__x << __r) | (__x >> (__n - __r));
 
-  return (__x >> -__r) | (__x << (__N + __r));
+  return (__x >> -__r) | (__x << (__n + __r));
 }
 
 template <class _Tp>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotr(_Tp __x, int __s) _NOEXCEPT {
   static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type");
-  const int __N = numeric_limits<_Tp>::digits;
-  int __r       = __s % __N;
+  const int __n = numeric_limits<_Tp>::digits;
+  int __r       = __s % __n;
 
   if (__r == 0)
     return __x;
 
   if (__r > 0)
-    return (__x >> __r) | (__x << (__N - __r));
+    return (__x >> __r) | (__x << (__n - __r));
 
-  return (__x << -__r) | (__x >> (__N + __r));
+  return (__x << -__r) | (__x >> (__n + __r));
 }
 
 #if _LIBCPP_STD_VER >= 20
diff --git a/libcxx/include/__chrono/zoned_time.h b/libcxx/include/__chrono/zoned_time.h
index 8cfa2122642c5e..a16ffcf1192b2e 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -201,8 +201,8 @@ template <class _TimeZonePtrOrName, class _Duration>
 zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>, choose = choose::earliest)
     -> zoned_time<common_type_t<_Duration, seconds>, __time_zone_representation<_TimeZonePtrOrName>>;
 
-template <class _Duration, class _TimeZonePtrOrName, class TimeZonePtr2>
-zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = choose::earliest)
+template <class _Duration, class _TimeZonePtrOrName, class _TimeZonePtr2>
+zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, _TimeZonePtr2>, choose = choose::earliest)
     -> zoned_time<common_type_t<_Duration, seconds>, __time_zone_representation<_TimeZonePtrOrName>>;
 
 using zoned_seconds = zoned_time<seconds>;
diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index 20c07559eae448..71783c55d72540 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -132,6 +132,7 @@ class
       : __out_it_(std::move(__out_it)), __args_(__args) {}
 #  endif
 
+public:
   basic_format_context(const basic_format_context&)            = delete;
   basic_format_context& operator=(const basic_format_context&) = delete;
 };
diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h
index 3444e9575e1af7..fb36d5cad78ec6 100644
--- a/libcxx/include/__memory_resource/polymorphic_allocator.h
+++ b/libcxx/include/__memory_resource/polymorphic_allocator.h
@@ -174,13 +174,15 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_TEMPLATE_VIS polymorphic_allocator {
 
   _LIBCPP_HIDE_FROM_ABI memory_resource* resource() const noexcept { return __res_; }
 
-  friend bool operator==(const polymorphic_allocator& __lhs, const polymorphic_allocator& __rhs) noexcept {
+  _LIBCPP_HIDE_FROM_ABI friend bool
+  operator==(const polymorphic_allocator& __lhs, const polymorphic_allocator& __rhs) noexcept {
     return *__lhs.resource() == *__rhs.resource();
   }
 
 #  if _LIBCPP_STD_VER <= 17
   // This overload is not specified, it was added due to LWG3683.
-  friend bool operator!=(const polymorphic_allocator& __lhs, const polymorphic_allocator& __rhs) noexcept {
+  _LIBCPP_HIDE_FROM_ABI friend bool
+  operator!=(const polymorphic_allocator& __lhs, const polymorphic_allocator& __rhs) noexcept {
     return *__lhs.resource() != *__rhs.resource();
   }
 #  endif
diff --git a/libcxx/include/__mutex/unique_lock.h b/libcxx/include/__mutex/unique_lock.h
index 5df791de4c7427..db506f32e89cee 100644
--- a/libcxx/include/__mutex/unique_lock.h
+++ b/libcxx/include/__mutex/unique_lock.h
@@ -84,16 +84,16 @@ class _LIBCPP_TEMPLATE_VIS unique_lock {
     return *this;
   }
 
-  void lock();
-  bool try_lock();
+  _LIBCPP_HIDE_FROM_ABI void lock();
+  _LIBCPP_HIDE_FROM_ABI bool try_lock();
 
   template <class _Rep, class _Period>
-  bool try_lock_for(const chrono::duration<_Rep, _Period>& __d);
+  _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __d);
 
   template <class _Clock, class _Duration>
-  bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
+  _LIBCPP_HIDE_FROM_ABI bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
 
-  void unlock();
+  _LIBCPP_HIDE_FROM_ABI void unlock();
 
   _LIBCPP_HIDE_FROM_ABI void swap(unique_lock& __u) _NOEXCEPT {
     std::swap(__m_, __u.__m_);
@@ -114,7 +114,7 @@ class _LIBCPP_TEMPLATE_VIS unique_lock {
 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(unique_lock);
 
 template <class _Mutex>
-void unique_lock<_Mutex>::lock() {
+_LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::lock() {
   if (__m_ == nullptr)
     __throw_system_error(EPERM, "unique_lock::lock: references null mutex");
   if (__owns_)
@@ -124,7 +124,7 @@ void unique_lock<_Mutex>::lock() {
 }
 
 template <class _Mutex>
-bool unique_lock<_Mutex>::try_lock() {
+_LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock() {
   if (__m_ == nullptr)
     __throw_system_error(EPERM, "unique_lock::try_lock: references null mutex");
   if (__owns_)
@@ -135,7 +135,7 @@ bool unique_lock<_Mutex>::try_lock() {
 
 template <class _Mutex>
 template <class _Rep, class _Period>
-bool unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
+_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");
   if (__owns_)
@@ -146,7 +146,7 @@ bool unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __
 
 template <class _Mutex>
 template <class _Clock, class _Duration>
-bool unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
+_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");
   if (__owns_)
@@ -156,7 +156,7 @@ bool unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Durat
 }
 
 template <class _Mutex>
-void unique_lock<_Mutex>::unlock() {
+_LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::unlock() {
   if (!__owns_)
     __throw_system_error(EPERM, "unique_lock::unlock: not locked");
   __m_->unlock();
diff --git a/libcxx/include/memory_resource b/libcxx/include/memory_resource
index 67411054820a1a..e98ca20aa058c3 100644
--- a/libcxx/include/memory_resource
+++ b/libcxx/include/memory_resource
@@ -72,7 +72,6 @@ namespace std::pmr {
 #  include <limits>
 #  include <mutex>
 #  include <new>
-#  include <stdexcept>
 #  include <tuple>
 #endif
 
diff --git a/libcxx/modules/std/mdspan.inc b/libcxx/modules/std/mdspan.inc
index ba3f3926c3abdd..5e65993383cdc0 100644
--- a/libcxx/modules/std/mdspan.inc
+++ b/libcxx/modules/std/mdspan.inc
@@ -15,6 +15,11 @@ export namespace std {
   // [mdspan.extents.dextents], alias template dextents
   using std::dextents;
 
+#  if _LIBCPP_STD_VER >= 26
+  // [mdspan.extents.dims]
+  using std::dims;
+#  endif // _LIBCPP_STD_VER >= 26
+
   // [mdspan.layout], layout mapping
   using std::layout_left;
   using std::layout_right;
diff --git a/libcxx/modules/std/new.inc b/libcxx/modules/std/new.inc
index 31c49057d0d286..76d0a29ed98f65 100644
--- a/libcxx/modules/std/new.inc
+++ b/libcxx/modules/std/new.inc
@@ -27,11 +27,13 @@ export namespace std {
 
   // [ptr.launder], pointer optimization barrier
   using std::launder;
-#if 0
+#if _LIBCPP_STD_VER >= 17
+#  if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
   // [hardware.interference], hardware interference size
   using std::hardware_constructive_interference_size;
   using std::hardware_destructive_interference_size;
-#endif
+#  endif
+#endif // _LIBCPP_STD_VER >= 17
 } // namespace std
 
 export {
diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index f0289dc44c6625..5de2d44994ad05 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -71,7 +71,7 @@ endif()
 # Note it has not been tested whether version 11 works.
 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test.cpp" "
 #include <version>
-#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 12
+#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11
   # error The libstdc++ version is too old.
 #endif
 int main(){}
@@ -83,7 +83,7 @@ try_compile(HAS_NEWER_STANDARD_LIBRARY
 
 if(NOT HAS_NEWER_STANDARD_LIBRARY)
   message(STATUS "Clang-tidy tests are disabled due to using "
-                 "stdlibc++ older than version 12")
+                 "stdlibc++ older than version 11")
   return()
 endif()
 message(STATUS "Clang-tidy tests are enabled.")
diff --git a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
index 6124bd30b19f04..9d5d37abde9584 100644
--- a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
+++ b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
@@ -77,8 +77,10 @@ header_exportable_declarations::header_exportable_declarations(
 
   list = Options.get("ExtraDeclarations");
   if (list)
-    for (auto decl : std::views::split(*list, ' '))
-      std::cout << "using ::" << std::string_view{decl.data(), decl.size()} << ";\n";
+    for (auto decl : std::views::split(*list, ' ')) {
+      auto common = decl | std::views::common;
+      std::cout << "using ::" << std::string{common.begin(), common.end()} << ";\n";
+    }
 }
 
 header_exportable_declarations::~header_exportable_declarations() {

``````````

</details>


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


More information about the libcxx-commits mailing list