Skip to content

Conversation

frederick-vs-ja
Copy link
Contributor

Currently, MSVC STL hasn't implemented the Mandates in [string.capacity]/8:

Mandates: OP has an integer-like type ([iterator.concept.winc]).

As a result, the following ill-formed program is accepted (Godbolt link):

#include <cstddef>
#include <string>

int main() {
    std::string{}.resize_and_overwrite(0, [](const char*, std::size_t) {
        struct NotIntegerLike {
            operator std::size_t() const {
                return 0;
            }
        };
        return NotIntegerLike{};
    });
}

This PR adds the missing static_assert and expands coverage for GH-2524 to all supported (cv-unqualified) integer-like types.

@frederick-vs-ja

This comment was marked as resolved.

@frederick-vs-ja frederick-vs-ja force-pushed the resize_and_overwrite-integer-like branch from e233688 to c761d14 Compare August 26, 2025 08:02
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Aug 26, 2025
@StephanTLavavej StephanTLavavej self-assigned this Aug 29, 2025
@StephanTLavavej StephanTLavavej removed their assignment Sep 6, 2025
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Sep 6, 2025
@StephanTLavavej
Copy link
Member

Thanks! 😻 I pushed very minor changes.

@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Sep 10, 2025
@StephanTLavavej
Copy link
Member

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

@StephanTLavavej StephanTLavavej merged commit a0239a5 into microsoft:main Sep 10, 2025
39 checks passed
@github-project-automation github-project-automation bot moved this from Merging to Done in STL Code Reviews Sep 10, 2025
@StephanTLavavej
Copy link
Member

Thanks for noticing and fixing this missing enforcement! 🎉 🚀 🐱

@frederick-vs-ja frederick-vs-ja deleted the resize_and_overwrite-integer-like branch September 10, 2025 23:43
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
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants