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

Prevent construction/conversion from nullptr #47

Open
mbs-c opened this issue Feb 4, 2022 · 1 comment
Open

Prevent construction/conversion from nullptr #47

mbs-c opened this issue Feb 4, 2022 · 1 comment

Comments

@mbs-c
Copy link

mbs-c commented Feb 4, 2022

When introducing string_view into an old codebase, it is quite easy to accidentally leave nonsensical assignments from or comparisons to nullptr in your code. Adding a deleted constructor as follows allows developers to easily identify the offending assignments and comparisons:

#if nssv_CPP11_OR_GREATER
    nssv_constexpr basic_string_view( std::nullptr_t ) nssv_noexcept = delete;
#endif

C++23 will also disallow constructing std::basic_string_view from nullptr: cplusplus/papers#887

@martinmoene
Copy link
Owner

Ah, thank you for the pointer Moritz @mbs-c, I wasn't yet aware of this.

I'll add the proposed constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants