[llvm] [ADT] Fix llvm::concat_iterator for `ValueT == common_base_class *` (PR #144744)

Javier Lopez-Gomez via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 23 06:15:48 PDT 2025


================
@@ -1032,13 +1032,17 @@ class concat_iterator
 
   static constexpr bool ReturnsByValue =
       !(std::is_reference_v<decltype(*std::declval<IterTs>())> && ...);
+  static constexpr bool ReturnsConvertiblePointer =
+      std::is_pointer_v<ValueT> &&
+      (std::is_convertible_v<decltype(*std::declval<IterTs>()), ValueT> && ...);
 
   using reference_type =
-      typename std::conditional_t<ReturnsByValue, ValueT, ValueT &>;
+      typename std::conditional_t<ReturnsByValue || ReturnsConvertiblePointer,
+                                  ValueT, ValueT &>;
----------------
jalopezg-git wrote:

> Doesn't this change the reference type in the case where all pointer types are the same? Prior to this PR, the `reference_type` used to be `T *&`, now it will become `T *`.

Yes, but only in case `ReturnsConvertiblePointer == true`, which requires that the return type of `operator*()` for all iterators in `ItersT` is convertible to `ValueT` (which should also be a pointer). 

> Similar for `handle_type`, doesn't this change the type from `T **` to `T *`?

Indeed (for the case above) -- IMO, that's not important, as `handle_type` has private visibility and it is only used to return values from `getHelper()` to `get()`.

https://github.com/llvm/llvm-project/pull/144744


More information about the llvm-commits mailing list