Skip to content

Commit f35d6ad

Browse files
Abseil Teamcopybara-github
authored andcommitted
Prevent conversion constructions from absl::Span to itself
The conversions invoke the wrong constructor and merely happen to work correctly. However, they break trivial-copyability, and may also break if the constructor behaviors diverge (such as if a lifetime attribute is added). PiperOrigin-RevId: 782932715 Change-Id: I280a03341887af241cf636c09f1c4318dc98fc16
1 parent 492fccd commit f35d6ad

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

absl/types/span.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ class ABSL_ATTRIBUTE_VIEW Span {
186186
// type C.
187187
template <typename C>
188188
using EnableIfConvertibleFrom =
189-
typename std::enable_if<span_internal::HasData<T, C>::value &&
190-
span_internal::HasSize<C>::value>::type;
189+
std::enable_if_t<!std::is_same_v<Span, std::remove_reference_t<C>> &&
190+
span_internal::HasData<T, C>::value &&
191+
span_internal::HasSize<C>::value>;
191192

192193
// Used to SFINAE-enable a function when the slice elements are const.
193194
template <typename U>

0 commit comments

Comments
 (0)