Skip to content

Prevent construction/conversion from nullptr #47

@mbs-c

Description

@mbs-c

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions