[libcxx-commits] [libcxx] d6b1448 - [libc++] Remove usage of `_LIBCPP_DEBUG` in `__comp_ref_type` and replace with `_LIBCPP_DEBUG_LEVEL`

Jordan Rupprecht via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 10 09:04:25 PST 2022


Author: Jordan Rupprecht
Date: 2022-02-10T09:03:07-08:00
New Revision: d6b1448809e4c6a2a5eca262bb917d5e76cf5206

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

LOG: [libc++] Remove usage of `_LIBCPP_DEBUG` in `__comp_ref_type` and replace with `_LIBCPP_DEBUG_LEVEL`

In libc++, checking specific `_LIBCPP_DEBUG_LEVEL` levels is used everywhere except in `comp_ref_type.h`. `_LIBCPP_DEBUG` is meant as a user-facing option, and internally libc++ should be checking the value of `_LIBCPP_DEBUG_LEVEL`.

The definition of `std::__debug_less` doesn't need to be hidden behind the macro, we can unconditionally expose it. It will be unused by `__comp_ref_type` unless debug mode is enabled.

This was suggested in D118940.

Reviewed By: #libc, philnik, Quuxplusone, ldionne

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

Added: 
    

Modified: 
    libcxx/include/__algorithm/comp_ref_type.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__algorithm/comp_ref_type.h b/libcxx/include/__algorithm/comp_ref_type.h
index b3012d4dab7f..79dda0afb29c 100644
--- a/libcxx/include/__algorithm/comp_ref_type.h
+++ b/libcxx/include/__algorithm/comp_ref_type.h
@@ -10,11 +10,8 @@
 #define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
 
 #include <__config>
-
-#ifdef _LIBCPP_DEBUG
-#  include <__debug>
-#  include <__utility/declval.h>
-#endif
+#include <__debug>
+#include <__utility/declval.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -22,8 +19,6 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#ifdef _LIBCPP_DEBUG
-
 template <class _Compare>
 struct __debug_less
 {
@@ -59,6 +54,8 @@ struct __debug_less
     __do_compare_assert(int, _LHS & __l, _RHS & __r) {
         _LIBCPP_ASSERT(!__comp_(__l, __r),
             "Comparator does not induce a strict weak ordering");
+        (void)__l;
+        (void)__r;
     }
 
     template <class _LHS, class _RHS>
@@ -67,13 +64,11 @@ struct __debug_less
     void __do_compare_assert(long, _LHS &, _RHS &) {}
 };
 
-#endif // _LIBCPP_DEBUG
-
 template <class _Comp>
 struct __comp_ref_type {
   // Pass the comparator by lvalue reference. Or in debug mode, using a
   // debugging wrapper that stores a reference.
-#ifndef _LIBCPP_DEBUG
+#if _LIBCPP_DEBUG_LEVEL == 0
   typedef _Comp& type;
 #else
   typedef __debug_less<_Comp> type;


        


More information about the libcxx-commits mailing list