-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Be a little more flexible about Span constructors. (#26701)
Before this change, this code: struct X { int member; }; struct Y : public X { }; Y object; Span<X> span(&Y, 1); would not compile, because we had std::is_same checks on the types (X and Y in this case). But this code is in fact safe as long as sizeof(Y) == sizeof(X), so we don't get confused about our object boundaries. This change replaces the std::is_same checks with sizeof() checks. But that leads to some situations being ambiguous, because the "can this pointer actually work for us?" check happens after overload resolution, so we explicitly do the std::is_convertible checks alongside sizeof to make sure that the pointer passed to our Span constructor will work.
- Loading branch information
1 parent
5a54e2f
commit 1118011
Showing
2 changed files
with
59 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters