[libcxx-commits] [libcxx] [libc++] Add a few _LIBCPP_ASSERT_INTERNALs to make sure internal invariants are kept (PR #114575)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 28 05:44:48 PST 2024


================
@@ -1990,10 +1998,12 @@ private:
   }
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __get_long_pointer() _NOEXCEPT {
+    _LIBCPP_ASSERT_INTERNAL(__rep_.__l.__is_long_, "String has to be long when trying to get the long pointer");
     return _LIBCPP_ASAN_VOLATILE_WRAPPER(__rep_.__l.__data_);
   }
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_pointer __get_long_pointer() const _NOEXCEPT {
+    _LIBCPP_ASSERT_INTERNAL(__rep_.__l.__is_long_, "String has to be long when trying to get the long pointer");
----------------
philnik777 wrote:

We're doing basically exactly the same in `__is_long()`, so I'm not sure how that would change the compiler's behaviour. FWIW Clang and GCC allow accessing an inactive union member in this kind of a scenario, so I don't think that's the problem.

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


More information about the libcxx-commits mailing list