Why is std::string_view::starts_with(const charT*) not noexcept?

Viewed 190

On cppreference there are three overloads for std::basic_string_view<CharT,Traits>::starts_with:

constexpr bool starts_with( basic_string_view sv ) const noexcept; (1)
constexpr bool starts_with( CharT c ) const noexcept; (2)
constexpr bool starts_with( const CharT* s ) const; (3)

Why is the third one not marked as noexcept? Similar with std::basic_string_view<CharT,Traits>::ends_with

1 Answers

Using pointers can potentially result in undefined behavior, that might throw an exception. What e.g. if s == nullptr or pointing to something really wrong?

Related