[libcxx-commits] [libcxx] [libcxx] improves diagnostics for containers with bad value types (PR #106296)
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 29 14:05:07 PDT 2024
================
@@ -76,8 +79,16 @@ struct __non_trivial_if<true, _Unique> {
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> > {
- static_assert(!is_const<_Tp>::value, "std::allocator does not support const types");
- static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
+ static_assert(!is_const<_Tp>::value, "'std::allocator' can only allocate non-const object types");
+ static_assert(!is_volatile<_Tp>::value, "'std::allocator' can only allocate non-volatile object types");
+ static_assert(!is_reference<_Tp>::value || !is_function<typename remove_reference<_Tp>::type>::value,
+ "'std::allocator' can only allocate object types; function references are not objects (consider using "
+ "a function pointer)");
+ static_assert(!is_reference<_Tp>::value,
+ "'std::allocator' can only allocate object types; references are not objects");
----------------
cjdb wrote:
I kicked the internal discussion off by asking if the average C++ programmer would be able to understand ` 'std::vector' can only allocate non-cv-qualified object types`, and the feedback I've received can be aggregated as roughly
* most C++ programmers don't know what the term "cv-qualified" means
* we should only mention relevant information, and mentioning "volatile" when `volatile` isn't used was repeatedly called out in particular
* most C++ programmers probably aren't going to know that "object" has a very different meaning to other languages
* most non-toolchain folks in the discussion seemed to prefer separate messages; toolchain folks were sort of ambivalent
What do you feel a single check will offer over independent checks?
https://github.com/llvm/llvm-project/pull/106296
More information about the libcxx-commits
mailing list