Decorate string_view members with nonnull attribute

Programming / Compilers / GCC - redi [138bc75d-0d04-0410-961f-82ee72b054a4] - 15 June 2018 16:47 EDT

The C++ committee has confirmed that passing a null pointer to the unary basic_string_view constructor is undefined. This removes the check from our implementation, and adds the nonnull attribute to warn when the compiler can detect undefined input.

- include/std/string_view (basic_string_view(const CharT*)): Remove check for null pointer and add nonnull attribute. (compare(const CharT*), compare(size_type, size_type, const CharT*)) (find(const CharT*, size_type), rfind(const CharT*, size_type)) (find_first_of(const CharT*, size_type)) (find_last_of(const CharT*, size_type)) (find_first_not_of(const CharT*, size_type)) (find_last_not_of(const CharT*, size_type)): Add nonnull attribute.
- testsuite/21_strings/basic_string_view/cons/char/nonnull.cc: New.
- testsuite/21_strings/basic_string_view/operations/compare/char/ nonnull.cc: New.
- testsuite/21_strings/basic_string_view/operations/find/char/ nonnull.cc: New.
- testsuite/21_strings/basic_string_view/operations/rfind/char/ nonnull.cc: New.

09e2d757369 Decorate string_view members with nonnull attribute
libstdc++-v3/ChangeLog | 16 +++++++++++
libstdc++-v3/include/std/string_view | 24 ++++++++--------
.../basic_string_view/cons/char/nonnull.cc | 29 +++++++++++++++++++
.../basic_string_view/cons/wchar_t/nonnull.cc | 29 +++++++++++++++++++
.../operations/compare/char/nonnull.cc | 29 +++++++++++++++++++
.../operations/find/char/nonnull.cc | 33 ++++++++++++++++++++++
.../operations/rfind/char/nonnull.cc | 29 +++++++++++++++++++
7 files changed, 178 insertions(+), 11 deletions(-)

Upstream: gcc.gnu.org


  • Share