[llvm-branch-commits] [libcxx] 03ee461 - [libc++] Consistently unparenthesize `numeric_limits<T>::max`. NFCI.

Arthur O'Dwyer via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 27 14:33:21 PST 2020


Author: Arthur O'Dwyer
Date: 2020-11-27T17:27:36-05:00
New Revision: 03ee46127621934c030d37f50aaefdef6bf9d4b0

URL: https://github.com/llvm/llvm-project/commit/03ee46127621934c030d37f50aaefdef6bf9d4b0
DIFF: https://github.com/llvm/llvm-project/commit/03ee46127621934c030d37f50aaefdef6bf9d4b0.diff

LOG: [libc++] Consistently unparenthesize `numeric_limits<T>::max`. NFCI.

I think people were sometimes parenthesizing `(foo::max)()` out of
misplaced concern that an unparenthesized `foo::max()` would trip up
Windows' `max(a,b)` macro. However, this is not the case: `max(a,b)`
should be tripped up only by an unparenthesized call to `foo::max(a,b)`,
and in fact we already do `_VSTD::max(a,b)` all over the place anyway
without any guards.

However, in order to do it without guards, we must also
wrap the header in _LIBCPP_PUSH_MACROS, which <span> was not.

Differential Revision: https://reviews.llvm.org/D92240

Added: 
    

Modified: 
    libcxx/include/charconv
    libcxx/include/span

Removed: 
    


################################################################################
diff  --git a/libcxx/include/charconv b/libcxx/include/charconv
index c830457154d7..4664f5b1d034 100644
--- a/libcxx/include/charconv
+++ b/libcxx/include/charconv
@@ -207,7 +207,7 @@ __mul_overflowed(unsigned char __a, _Tp __b, unsigned char& __r)
 {
     auto __c = __a * __b;
     __r = __c;
-    return __c > (numeric_limits<unsigned char>::max)();
+    return __c > numeric_limits<unsigned char>::max();
 }
 
 template <typename _Tp>
@@ -216,7 +216,7 @@ __mul_overflowed(unsigned short __a, _Tp __b, unsigned short& __r)
 {
     auto __c = __a * __b;
     __r = __c;
-    return __c > (numeric_limits<unsigned short>::max)();
+    return __c > numeric_limits<unsigned short>::max();
 }
 
 template <typename _Tp>
@@ -227,7 +227,7 @@ __mul_overflowed(_Tp __a, _Tp __b, _Tp& __r)
 #if !defined(_LIBCPP_COMPILER_MSVC)
     return __builtin_mul_overflow(__a, __b, &__r);
 #else
-    bool __did = __b && ((numeric_limits<_Tp>::max)() / __b) < __a;
+    bool __did = __b && (numeric_limits<_Tp>::max() / __b) < __a;
     __r = __a * __b;
     return __did;
 #endif
@@ -435,7 +435,7 @@ __sign_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, _Ts... __args)
     }
     else
     {
-        if (__x <= (__tl::max)())
+        if (__x <= __tl::max())
         {
             __value = __x;
             return __r;
@@ -526,7 +526,7 @@ __from_chars_atoi(const char* __first, const char* __last, _Tp& __value)
             auto __p = __tx::__read(__first, __last, __a, __b);
             if (__p == __last || !__in_pattern(*__p))
             {
-                __output_type __m = (numeric_limits<_Tp>::max)();
+                __output_type __m = numeric_limits<_Tp>::max();
                 if (__m >= __a && __m - __a >= __b)
                 {
                     __value = __a + __b;
@@ -581,7 +581,7 @@ __from_chars_integral(const char* __first, const char* __last, _Tp& __value,
 
             if (__p == __last || !__in_pattern(*__p, __base))
             {
-                if ((__tl::max)() - __a >= __b)
+                if (__tl::max() - __a >= __b)
                 {
                     __value = __a + __b;
                     return {__p, {}};

diff  --git a/libcxx/include/span b/libcxx/include/span
index b307c98aee20..4f63d0ac4e1f 100644
--- a/libcxx/include/span
+++ b/libcxx/include/span
@@ -132,11 +132,14 @@ template<class Container>
 #pragma GCC system_header
 #endif
 
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 17
 
-inline constexpr size_t dynamic_extent = (numeric_limits<size_t>::max)();
+inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
 template <typename _Tp, size_t _Extent = dynamic_extent> class span;
 
 
@@ -546,4 +549,6 @@ template<class _Container>
 
 _LIBCPP_END_NAMESPACE_STD
 
+_LIBCPP_POP_MACROS
+
 #endif // _LIBCPP_SPAN


        


More information about the llvm-branch-commits mailing list