[libcxx-commits] [PATCH] D95251: Remove noexcept from basic_string::find and implementation functions.

Jonathan Wakely via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 25 02:13:45 PST 2021

jwakely added a comment.

In D95251#2516668 <https://reviews.llvm.org/D95251#2516668>, @CaseyCarter wrote:

> It's probably a wide vs. narrow contract thing. The find overloads that take const char*, for example, have a precondition that the pointer is non-null. Under the so-called "Lakos rule" they would/could/should be "Throws: Nothing" but not noexcept.

Yes, exactly this. The string and string_view overloads all have correct noexcept specifiers in the standard (and we've relitigated that several times already). Operations on char_traits cannot throw, whether they are `noexcept` or not. But due to the Lakos rule, they can't all be marked `noexcept` (LEWG have agreed to change the rule, but that hasn't changed anything yet and I do not want to use the issues list to add `noexcept` to "*Throws: nothing" functions one-by-one throughout the library). I agree with Casey's interpretation of "Operations on X shall not throw exceptions." But I also think it could be clearer so that nobody interprets it another way.

If libc++ doesn't want to use exceptions to diagnose precondition violations in the `find` members that have narrow contracts, then just add `noexcept` to all your `find` overloads (which is what libstdc++ does). The standard is correct though.

  rG LLVM Github Monorepo



More information about the libcxx-commits mailing list