[libcxx-commits] [PATCH] D93912: [libc++][P1679] add string contains

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 11 19:01:32 PST 2021

Quuxplusone added inline comments.

Comment at: libcxx/include/string:1450
+    bool contains(const value_type* __s) const
+    { return __self_view(data(), size()).contains(__s); }
zoecarver wrote:
> Thoughts on making this one noexcept as well? (I know it's not noexcept in the standard, does anyone know the reason for that?)
[Lakos Rule.](https://quuxplusone.github.io/blog/2018/04/25/the-lakos-rule/) If `__s` is null, or points to a non-null-terminated array, then this overload has UB; whereas the other two overloads never have UB.

No useful opinion from me on making this one noexcept. Personally I can never remember whether vendors are allowed to add `noexcept`, or `constexpr`, or neither. I also don't know if libc++ thinks it's OK to add either keyword if it's not mandated by the standard, because that might be a portability trap for users (they rely on its being noexcept and then their code breaks when they switch to libstdc++ or something).

  rG LLVM Github Monorepo



More information about the libcxx-commits mailing list