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

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 9 11:34:00 PDT 2024


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

>From 4fa8ad2028a2cf750395ab59a0d84429c093ddb9 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Fri, 9 Aug 2024 20:27:05 +0200
Subject: [PATCH] [libc++] Fix clang-tidy issues and re-enable it in the CI

---
 libcxx/include/__atomic/atomic_ref.h             |  2 +-
 libcxx/include/__bit/rotate.h                    | 16 ++++++++--------
 libcxx/include/__chrono/zoned_time.h             |  4 ++--
 libcxx/include/__format/format_context.h         |  1 +
 .../__memory_resource/polymorphic_allocator.h    |  6 ++++--
 libcxx/include/memory_resource                   |  1 -
 .../test/tools/clang_tidy_checks/CMakeLists.txt  |  4 ++--
 .../header_exportable_declarations.cpp           |  2 +-
 8 files changed, 19 insertions(+), 17 deletions(-)

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/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/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..66260841fe2ab5 100644
--- a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
+++ b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
@@ -78,7 +78,7 @@ 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";
+      std::cout << "using ::" << std::string{decl.data(), decl.size()} << ";\n";
 }
 
 header_exportable_declarations::~header_exportable_declarations() {



More information about the libcxx-commits mailing list