[llvm] 92416b6 - [ADT] Work around `enumerate` compilation error with modules enabled

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 20 11:35:53 PDT 2023


Author: Jakub Kuderski
Date: 2023-03-20T14:27:51-04:00
New Revision: 92416b63a57b74689abc175bcafd97b674ff9728

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

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

This manifests on Apple clang 14 with `-DLLVM_ENABLE_MODULES=1` and
`-DLLVM_ENABLE_ASSERTIONS=1` and seems like a host compiler bug.

Sample compilation failure:
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/52513/consoleFull#-458239162a1ca8a51-895e-46c6-af87-ce24fa4cd561.

Reviewed By: aprantl

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index bf33d79801065..8d739106bccbb 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -2385,10 +2385,16 @@ struct index_stream {
 ///
 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 
diff erent 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 
diff erent length");
+#endif
+  }
   using enumerator = detail::zippy<detail::zip_enumerator, detail::index_stream,
                                    FirstRange, RestRanges...>;
   return enumerator(detail::index_stream{}, std::forward<FirstRange>(First),


        


More information about the llvm-commits mailing list