[libcxx-commits] [PATCH] D92240: [libc++] Consistently unparenthesize `numeric_limits<T>::max`. NFCI.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 27 11:20:03 PST 2020


Quuxplusone created this revision.
Quuxplusone added a reviewer: ldionne.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Quuxplusone requested review of this revision.

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.

(For reference: The charconv pieces were originally added in D41458 <https://reviews.llvm.org/D41458>.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92240

Files:
  libcxx/include/charconv
  libcxx/include/span


Index: libcxx/include/span
===================================================================
--- libcxx/include/span
+++ libcxx/include/span
@@ -136,7 +136,7 @@
 
 #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;
 
 
Index: libcxx/include/charconv
===================================================================
--- libcxx/include/charconv
+++ libcxx/include/charconv
@@ -207,7 +207,7 @@
 {
     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 @@
 {
     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 @@
 #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 @@
     }
     else
     {
-        if (__x <= (__tl::max)())
+        if (__x <= __tl::max())
         {
             __value = __x;
             return __r;
@@ -526,7 +526,7 @@
             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 @@
 
             if (__p == __last || !__in_pattern(*__p, __base))
             {
-                if ((__tl::max)() - __a >= __b)
+                if (__tl::max() - __a >= __b)
                 {
                     __value = __a + __b;
                     return {__p, {}};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92240.308094.patch
Type: text/x-patch
Size: 2166 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201127/1481d783/attachment-0001.bin>


More information about the libcxx-commits mailing list