This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Add workaround to avoid breaking users of <span> when <ranges> are disabled
ClosedPublic

Authored by ldionne on Mar 15 2022, 2:13 PM.

Details

Reviewers
ldionne
Group Reviewers
Restricted Project
Summary

Back in 3a208c68942e, we implemented the range-based constructor for <span>.
However, in doing so, we removed a previous non-standard constructor that
we provided before shipping <ranges>. Unfortunately, that breaks code that
was relying on a range-based constructor until we ship all of <ranges>.

This patch reintroduces the old non-conforming constructors and tests
that were removed in 3a208c68942e and uses them whenever <ranges> is
not provided (e.g. in LLVM 14). This is only a temporary workaround
until we enable <ranges> by default in C++20, which should hopefully
happen by LLVM 15.

The goal is to cherry-pick this workaround back to the LLVM 14 release
branch, since I suspect the constructor removal may otherwise cause
breakage out there, like the breakage I saw internally.

We could have avoided this situation by waiting for C++20 to be finalized
before shipping std::span. For example, we could have guarded it with
something like _LIBCPP_HAS_NO_INCOMPLETE_RANGES to prevent users from
accidentally starting to depend on it before it is stable. We did not
have these mechanisms when std::span was first implemented, though.

NOTE: This is a pretty modified version of d4c39f1ab94 since that one didn't apply properly onto the release/14.x branch.

(cherry picked from commit d4c39f1ab94abc1dd4fff1e82dd4fa97265940e1)

Diff Detail

Event Timeline

ldionne created this revision.Mar 15 2022, 2:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2022, 2:13 PM
ldionne requested review of this revision.Mar 15 2022, 2:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2022, 2:13 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne accepted this revision as: Restricted Project.Mar 15 2022, 2:13 PM

This is aimed for the release/14.x branch. I'm uploading a patch to run CI on it since the cherry-pick was pretty manual. I'll land this if CI passes.

ldionne accepted this revision.Apr 5 2022, 9:37 AM

This was landed as add3ab7f4c8a7f25c2940889d397cbdc9f267666 onto release/14.x.

This revision is now accepted and ready to land.Apr 5 2022, 9:37 AM
ldionne closed this revision.Apr 5 2022, 9:37 AM