You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[libcxx] improves diagnostics for containers with bad value types
`std::vector<int&>` generates nearly 170 lines of diagnostic, most of
which are redundant, and it's only helpful if you are already familiar
with the rule that containers can't hold reference types. This commit
reduces it to only a handful of lines, all of which are dedicated to
clearly communicating the problem. It also applies this to all the
other containers, and for all non-cv-qualified and non-object types.
These static_asserts are placed at the very top of each container
because they short-circuit further instantiation errors, thereby
leading a smaller set of diagnostics for the programmer. Placing them
in `std::allocator` (which is the common denominator for all containers)
doesn't do the short circuiting, and we thus end up with several
unhelpful diagnostics after the helpful one.
This commit only cleans up things that are already diagnosed as
compile-time errors. In particular, `map<int&&, int>` should be
ill-formed, per [associative.reqmts.general]/p8. libc++ and libstdc++
currently permit that, but not `map<int&, int>`. As such, this
commit only adds a static assert for `map<K&, V>`, and defers diagnosing
valid productions that should be ill-formed to a future commit.
static_assert(!is_reference<_Tp>::value || !is_function<typename remove_reference<_Tp>::type>::value, "'std::array' can only hold object types; function references are not objects (consider using a function pointer)");
175
+
static_assert(!is_reference<_Tp>::value, "'std::array' can only hold object types; references are not objects");
176
+
static_assert(!is_function<_Tp>::value, "'std::array' can only hold object types; functions are not objects (consider using a function pointer)");
177
+
static_assert(!is_void<_Tp>::value, "'std::array' can only hold object types; 'void' is not an object");
178
+
170
179
using __trivially_relocatable = __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, array, void>;
static_assert(!is_const<_Tp>::value, "'std::deque' can only hold non-const types");
478
+
static_assert(!is_volatile<_Tp>::value, "'std::deque' can only hold non-volatile types");
479
+
static_assert(!is_reference<_Tp>::value || !is_function<typename remove_reference<_Tp>::type>::value, "'std::deque' can only hold object types; function references are not objects (consider using a function pointer)");
480
+
static_assert(!is_reference<_Tp>::value, "'std::deque' can only hold object types; references are not objects");
481
+
static_assert(!is_function<_Tp>::value, "'std::deque' can only hold object types; functions are not objects (consider using a function pointer)");
482
+
static_assert(!is_void<_Tp>::value, "'std::deque' can only hold object types; 'void' is not an object");
static_assert(!is_const<_Tp>::value, "'std::forward_list' can only hold non-const types");
767
+
static_assert(!is_volatile<_Tp>::value, "'std::forward_list' can only hold non-volatile types");
768
+
static_assert(!is_reference<_Tp>::value || !is_function<typename remove_reference<_Tp>::type>::value, "'std::forward_list' can only hold object types; function references are not objects (consider using a function pointer)");
769
+
static_assert(!is_reference<_Tp>::value, "'std::forward_list' can only hold object types; references are not objects");
770
+
static_assert(!is_function<_Tp>::value, "'std::forward_list' can only hold object types; functions are not objects (consider using a function pointer)");
771
+
static_assert(!is_void<_Tp>::value, "'std::forward_list' can only hold object types; 'void' is not an object");
class_LIBCPP_TEMPLATE_VIS list : private __list_imp<_Tp, _Alloc> {
791
+
static_assert(!is_const<_Tp>::value, "'std::list' can only hold non-const types");
792
+
static_assert(!is_volatile<_Tp>::value, "'std::list' can only hold non-volatile types");
793
+
static_assert(!is_reference<_Tp>::value || !is_function<typename remove_reference<_Tp>::type>::value, "'std::list' can only hold object types; function references are not objects (consider using a function pointer)");
794
+
static_assert(!is_reference<_Tp>::value, "'std::list' can only hold object types; references are not objects");
795
+
static_assert(!is_function<_Tp>::value, "'std::list' can only hold object types; functions are not objects (consider using a function pointer)");
796
+
static_assert(!is_void<_Tp>::value, "'std::list' can only hold object types; 'void' is not an object");
0 commit comments