[libc++] Fix a few warnings in system headers with GCC
This isn't fixing all of them, but at least it's making some progress.
Differential Revision: https://reviews.llvm.org/D106283
NOKEYCHECK=True
GitOrigin-RevId: 2e4755ff6058b5032b77ccca04aa6dab7db081a5
diff --git a/include/__config b/include/__config
index 9a5343c..3cf2369 100644
--- a/include/__config
+++ b/include/__config
@@ -531,7 +531,7 @@
#define _LIBCPP_NORETURN __attribute__((noreturn))
-#if !__EXCEPTIONS
+#if !defined(__EXCEPTIONS)
# define _LIBCPP_NO_EXCEPTIONS
#endif
@@ -1023,7 +1023,8 @@
#if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
_Pragma("GCC diagnostic push") \
- _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
+ _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
+ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
# define _LIBCPP_SUPPRESS_DEPRECATED_POP \
_Pragma("GCC diagnostic pop")
#else
diff --git a/include/__hash_table b/include/__hash_table
index f28100e..df0f7c8 100644
--- a/include/__hash_table
+++ b/include/__hash_table
@@ -741,9 +741,9 @@
private:
#if _LIBCPP_DEBUG_LEVEL == 2
_LIBCPP_INLINE_VISIBILITY
- __hash_const_local_iterator(__next_pointer __node, size_t __bucket,
+ __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
size_t __bucket_count, const void* __c) _NOEXCEPT
- : __node_(__node),
+ : __node_(__node_ptr),
__bucket_(__bucket),
__bucket_count_(__bucket_count)
{
@@ -753,9 +753,9 @@
}
#else
_LIBCPP_INLINE_VISIBILITY
- __hash_const_local_iterator(__next_pointer __node, size_t __bucket,
+ __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
size_t __bucket_count) _NOEXCEPT
- : __node_(__node),
+ : __node_(__node_ptr),
__bucket_(__bucket),
__bucket_count_(__bucket_count)
{
diff --git a/include/__ranges/transform_view.h b/include/__ranges/transform_view.h
index 9a7ffa1..4243dc0 100644
--- a/include/__ranges/transform_view.h
+++ b/include/__ranges/transform_view.h
@@ -360,7 +360,7 @@
__sentinel() = default;
_LIBCPP_HIDE_FROM_ABI
- constexpr explicit __sentinel(sentinel_t<_Base> __end_) : __end_(__end_) {}
+ constexpr explicit __sentinel(sentinel_t<_Base> __end) : __end_(__end) {}
// Note: `__i` should always be `__sentinel<false>`, but directly using
// `__sentinel<false>` is ill-formed when `_Const` is false
diff --git a/include/barrier b/include/barrier
index 0ba9d20..e26dba6 100644
--- a/include/barrier
+++ b/include/barrier
@@ -107,7 +107,6 @@
template<class _CompletionF>
class __barrier_base {
-
ptrdiff_t __expected;
unique_ptr<__barrier_algorithm_base,
void (*)(__barrier_algorithm_base*)> __base;
@@ -146,7 +145,7 @@
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
void wait(arrival_token&& __old_phase) const
{
- auto const __test_fn = [=]() -> bool {
+ auto const __test_fn = [this, __old_phase]() -> bool {
return __phase.load(memory_order_acquire) != __old_phase;
};
__libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
diff --git a/include/charconv b/include/charconv
index 4a5c65d..de34112 100644
--- a/include/charconv
+++ b/include/charconv
@@ -612,13 +612,13 @@
return __subject_seq_combinator(
__first, __last, __value,
- [](const char* __p, const char* __last, _Tp& __value,
+ [](const char* __p, const char* __lastx, _Tp& __value,
int __base) -> from_chars_result {
using __tl = numeric_limits<_Tp>;
auto __digits = __tl::digits / log2f(float(__base));
_Tp __a = __in_pattern(*__p++, __base).__val, __b = 0;
- for (int __i = 1; __p != __last; ++__i, ++__p)
+ for (int __i = 1; __p != __lastx; ++__i, ++__p)
{
if (auto __c = __in_pattern(*__p, __base))
{
@@ -636,7 +636,7 @@
break;
}
- if (__p == __last || !__in_pattern(*__p, __base))
+ if (__p == __lastx || !__in_pattern(*__p, __base))
{
if (__tl::max() - __a >= __b)
{
diff --git a/include/cmath b/include/cmath
index a520685c..adf83c2 100644
--- a/include/cmath
+++ b/include/cmath
@@ -621,7 +621,7 @@
if (__t == 1) return __b;
const _Fp __x = __a + __t * (__b - __a);
- if (__t > 1 == __b > __a)
+ if ((__t > 1) == (__b > __a))
return __b < __x ? __x : __b;
else
return __x < __b ? __x : __b;
diff --git a/include/compare b/include/compare
index c7bfb45..e924bff 100644
--- a/include/compare
+++ b/include/compare
@@ -449,7 +449,7 @@
return _StrongOrd;
}
-template <class ..._Ts>
+template <class ..._Ts, bool _False = false>
constexpr auto __get_comp_type() {
using _CCC = _ClassifyCompCategory;
constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
@@ -463,7 +463,7 @@
else if constexpr (_Cat == _StrongOrd)
return strong_ordering::equivalent;
else
- static_assert(_Cat != _Cat, "unhandled case");
+ static_assert(_False, "unhandled case");
}
} // namespace __comp_detail
diff --git a/include/memory b/include/memory
index 4f73a81..fdb8943 100644
--- a/include/memory
+++ b/include/memory
@@ -796,7 +796,7 @@
ptrdiff_t _Np = __end1 - __begin1;
__end2 -= _Np;
if (_Np > 0)
- _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
+ _VSTD::memcpy(static_cast<void*>(__end2), static_cast<void const*>(__begin1), _Np * sizeof(_Tp));
}
struct __destruct_n
diff --git a/include/random b/include/random
index 85d03ee..4a8c2a7 100644
--- a/include/random
+++ b/include/random
@@ -1731,7 +1731,7 @@
template <unsigned long long __a, unsigned long long __c,
unsigned long long __m, unsigned long long _Mp,
bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a),
- bool _OverflowOK = ((__m|__m-1) > __m), // m = 2^n
+ bool _OverflowOK = ((__m | (__m-1)) > __m), // m = 2^n
bool _SchrageOK = (__a != 0 && __m != 0 && __m % __a <= __m / __a)> // r <= q
struct __lce_alg_picker
{
diff --git a/include/regex b/include/regex
index 55f1d34..e47cf9f 100644
--- a/include/regex
+++ b/include/regex
@@ -2003,14 +2003,14 @@
{
typedef __owns_one_state<_CharT> base;
- bool __multiline;
+ bool __multiline_;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__l_anchor_multiline(bool __multiline, __node<_CharT>* __s)
- : base(__s), __multiline(__multiline) {}
+ : base(__s), __multiline_(__multiline) {}
virtual void __exec(__state&) const;
};
@@ -2025,7 +2025,7 @@
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
}
- else if (__multiline &&
+ else if (__multiline_ &&
!__s.__at_first_ &&
__is_eol(*_VSTD::prev(__s.__current_)))
{
@@ -4574,7 +4574,7 @@
if (__hd == -1)
__throw_regex_error<regex_constants::error_escape>();
__sum = 16 * __sum + static_cast<unsigned>(__hd);
- // drop through
+ // fallthrough
case 'x':
++__first;
if (__first == __last)
diff --git a/include/semaphore b/include/semaphore
index 20c9b1e..906f62e 100644
--- a/include/semaphore
+++ b/include/semaphore
@@ -98,7 +98,7 @@
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
void acquire()
{
- auto const __test_fn = [=]() -> bool {
+ auto const __test_fn = [this]() -> bool {
auto __old = __a.load(memory_order_relaxed);
return (__old != 0) && __a.compare_exchange_strong(__old, __old - 1, memory_order_acquire, memory_order_relaxed);
};
@@ -108,7 +108,7 @@
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
bool try_acquire_for(chrono::duration<Rep, Period> const& __rel_time)
{
- auto const __test_fn = [=]() -> bool {
+ auto const __test_fn = [this]() -> bool {
auto __old = __a.load(memory_order_acquire);
while(1) {
if (__old == 0)