[PATCH] D146340: [ADT] Work around `enumerate` compilation error with modules enabled

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 18 14:43:12 PDT 2023


kuhar updated this revision to Diff 506333.
kuhar added a comment.

Do not calculate sizes in non-debug builds


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146340/new/

https://reviews.llvm.org/D146340

Files:
  llvm/include/llvm/ADT/STLExtras.h


Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -2385,10 +2385,16 @@
 ///
 template <typename FirstRange, typename... RestRanges>
 auto enumerate(FirstRange &&First, RestRanges &&...Rest) {
-  assert((sizeof...(Rest) == 0 ||
-          all_equal({std::distance(adl_begin(First), adl_end(First)),
-                     std::distance(adl_begin(Rest), adl_end(Rest))...})) &&
-         "Ranges have different length");
+  if constexpr (sizeof...(Rest) != 0) {
+#ifndef NDEBUG
+    // Note: Create an array instead of an initializer list to work around an
+    // Apple clang 14 compiler bug.
+    size_t sizes[] = {
+        static_cast<size_t>(std::distance(adl_begin(First), adl_end(First))),
+        static_cast<size_t>(std::distance(adl_begin(Rest), adl_end(Rest)))...};
+    assert(all_equal(sizes) && "Ranges have different length");
+#endif
+  }
   using enumerator = detail::zippy<detail::zip_enumerator, detail::index_stream,
                                    FirstRange, RestRanges...>;
   return enumerator(detail::index_stream{}, std::forward<FirstRange>(First),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146340.506333.patch
Type: text/x-patch
Size: 1215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230318/24f6497d/attachment.bin>


More information about the llvm-commits mailing list