[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 08:48:38 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:
> some test coverage would be good either way - to demonstrate what breaks if such changes were to occur (ie: assignability of a dereference expression (`*concat_iter = other_ptr`) would fail to compile if the reference type changed from `T*&` to `T*`)
Not sure I completely understood your intent; however, I have added one additional test that checks that returning by reference where appropriate is still okay.
Such pattern can also been seen, e.g., in https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/SCF/Transforms/ParallelLoopFusion.cpp#L217.
PTAL and let me know if I still need to apply some changes to this PR.
https://github.com/llvm/llvm-project/pull/144744
More information about the llvm-commits
mailing list