[libcxx] [llvm] [libc++] Diagnose when nullptrs are passed to string APIs (PR #122790)

Nikolas Klauser via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 23 01:57:54 PST 2025


================
@@ -1037,13 +1037,14 @@ public:
 #  endif // _LIBCPP_CXX03_LANG
 
   template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) {
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* _LIBCPP_DIAGNOSE_NONNULL __s) {
----------------
philnik777 wrote:

Yes. `_Nonnull` makes passing a nullptr erroneus behaviour, but not UB. That's why I chose that over `[[gnu::nonnull]]`.

https://github.com/llvm/llvm-project/pull/122790


More information about the llvm-commits mailing list