Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defend sequence container constructors from bad CTAD #4254

Merged

Conversation

StephanTLavavej
Copy link
Member

Found by the upcoming libcxx update, where they test CTAD for (Iter, Iter, BadAlloc) and expect it to SFINAE away.

(The explicit deduction guides are already constrained to take only things that qualify as allocators. The issue is that every constructor generates an implicit guide, and those can lead to the container being instantiated with a BadAlloc unless we guard against that.)

It's actually unclear to me whether this is guaranteed by the Standard, but the defense is simple and we already do this in basic_string.

Found by libcxx testing (Iter, Iter, BadAlloc).
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Dec 10, 2023
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner December 10, 2023 07:47
@frederick-vs-ja
Copy link
Contributor

Related to #4060 (but not exactly that issue).

@StephanTLavavej StephanTLavavej self-assigned this Dec 14, 2023
@StephanTLavavej
Copy link
Member Author

I'm speculatively mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@CaseyCarter
Copy link
Member

It's actually unclear to me whether this is guaranteed by the Standard, but the defense is simple and we already do this in basic_string.

It's not guaranteed but IMO it should be. The Standard tells us to do so explicitly for basic_string.

The Standard has wording for deduction guides but not for constructors. This is slightly confusing since pre-Standard language in WG21 used "implicit" and "explicit" deduction guides to distinguish between the function templates derived from constructors for use in CTAD and those derived from deduction guides.

We ought to file an LWG issue.

@StephanTLavavej StephanTLavavej merged commit ca641a0 into microsoft:main Dec 14, 2023
35 checks passed
@StephanTLavavej StephanTLavavej deleted the sequence-container-ctad branch December 14, 2023 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants