@@ -1032,13 +1032,22 @@ class concat_iterator
1032
1032
1033
1033
static constexpr bool ReturnsByValue =
1034
1034
!(std::is_reference_v<decltype (*std::declval<IterTs>())> && ...);
1035
+ static constexpr bool ReturnsConvertiblePointer =
1036
+ std::is_pointer_v<ValueT> &&
1037
+ (std::is_convertible_v<decltype (*std::declval<IterTs>()), ValueT> && ...);
1035
1038
1036
1039
using reference_type =
1037
- typename std::conditional_t <ReturnsByValue, ValueT, ValueT &>;
1038
-
1039
- using handle_type =
1040
- typename std::conditional_t <ReturnsByValue, std::optional<ValueT>,
1041
- ValueT *>;
1040
+ typename std::conditional_t <ReturnsByValue || ReturnsConvertiblePointer,
1041
+ ValueT, ValueT &>;
1042
+
1043
+ using optional_value_type =
1044
+ std::conditional_t <ReturnsByValue, std::optional<ValueT>, ValueT *>;
1045
+ // handle_type is used to return an optional value from `getHelper()`. If
1046
+ // the type resulting from dereferencing all IterTs is a pointer that can be
1047
+ // converted to `ValueT`, use that pointer type instead to avoid implicit
1048
+ // conversion issues.
1049
+ using handle_type = typename std::conditional_t <ReturnsConvertiblePointer,
1050
+ ValueT, optional_value_type>;
1042
1051
1043
1052
// / We store both the current and end iterators for each concatenated
1044
1053
// / sequence in a tuple of pairs.
@@ -1088,7 +1097,7 @@ class concat_iterator
1088
1097
if (Begin == End)
1089
1098
return {};
1090
1099
1091
- if constexpr (ReturnsByValue)
1100
+ if constexpr (ReturnsByValue || ReturnsConvertiblePointer )
1092
1101
return *Begin;
1093
1102
else
1094
1103
return &*Begin;
@@ -1105,8 +1114,12 @@ class concat_iterator
1105
1114
1106
1115
// Loop over them, and return the first result we find.
1107
1116
for (auto &GetHelperFn : GetHelperFns)
1108
- if (auto P = (this ->*GetHelperFn)())
1109
- return *P;
1117
+ if (auto P = (this ->*GetHelperFn)()) {
1118
+ if constexpr (ReturnsConvertiblePointer)
1119
+ return P;
1120
+ else
1121
+ return *P;
1122
+ }
1110
1123
1111
1124
llvm_unreachable (" Attempted to get a pointer from an end concat iterator!" );
1112
1125
}
0 commit comments