-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libcxx] improves diagnostics for containers with bad value types #106296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
5529499
1e6b81b
6c1e1e3
938299d
65346a3
472ffcf
7596a2e
25e999f
5a1b902
99a4509
45c85d6
dbf872a
e596964
e2d65c0
0487281
6d9ce9e
c49b7e8
eb2fd68
55a2e7a
d9043c4
ab41024
7bd03b3
ef9d9c3
f0f88d7
bb82c95
33a452d
6981a2a
9fe3f4a
b97942e
02ffa16
f75d1ae
20e0996
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,12 @@ | |
| #include <__memory/allocator_traits.h> | ||
| #include <__type_traits/is_const.h> | ||
| #include <__type_traits/is_constant_evaluated.h> | ||
| #include <__type_traits/is_function.h> | ||
| #include <__type_traits/is_reference.h> | ||
| #include <__type_traits/is_same.h> | ||
| #include <__type_traits/is_void.h> | ||
| #include <__type_traits/is_volatile.h> | ||
| #include <__type_traits/remove_reference.h> | ||
| #include <__utility/forward.h> | ||
| #include <cstddef> | ||
| #include <new> | ||
|
|
@@ -76,8 +79,10 @@ 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' cannot allocate const types"); | ||
| static_assert(!is_volatile<_Tp>::value, "'std::allocator' cannot allocate volatile types"); | ||
| static_assert(!is_reference<_Tp>::value, "'std::allocator' cannot allocate references"); | ||
| static_assert(!is_function<_Tp>::value, "'std::allocator' cannot allocate functions"); | ||
|
||
|
|
||
| public: | ||
| typedef size_t size_type; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef _LIBCPP___TYPE_TRAITS_DIAGNOSTIC_UTILITIES_H | ||
| #define _LIBCPP___TYPE_TRAITS_DIAGNOSTIC_UTILITIES_H | ||
|
|
||
| #include <__config> | ||
| #include <__type_traits/is_array.h> | ||
| #include <__type_traits/is_const.h> | ||
| #include <__type_traits/is_reference.h> | ||
| #include <__type_traits/is_unbounded_array.h> | ||
| #include <__type_traits/is_void.h> | ||
| #include <__type_traits/is_volatile.h> | ||
|
|
||
| #pragma GCC system_header | ||
cjdb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #if _LIBCPP_STD_VER >= 20 | ||
| # define _LIBCPP_CHECK_CONTAINER_VALUE_TYPE_IS_NOT_ARRAY_BEFORE_CXX20(_Container, _Tp) | ||
| #else | ||
| # define _LIBCPP_CHECK_CONTAINER_VALUE_TYPE_IS_NOT_ARRAY_BEFORE_CXX20(_Container, _Tp) \ | ||
| ; \ | ||
cjdb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static_assert(!is_array<_Tp>::value, "'std::" _Container "' cannot hold C arrays before C++20") | ||
| #endif | ||
|
|
||
| // Per https://eel.is/c++draft/containers#container.reqmts-64, allocator-aware containers must have an | ||
| // allocator that meets the Cpp17Allocator requirements (https://eel.is/c++draft/allocator.requirements). | ||
| // In particular, this means that containers should only accept non-cv-qualified object types, and | ||
| // types that are Cpp17Erasable. | ||
| #define _LIBCPP_CHECK_CONTAINER_VALUE_TYPE_REQUIREMENTS_BASE(_Container, _Tp) \ | ||
|
||
| static_assert(!is_const<_Tp>::value, "'std::" _Container "' cannot hold const types"); \ | ||
| static_assert(!is_volatile<_Tp>::value, "'std::" _Container "' cannot hold volatile types"); \ | ||
| static_assert(!is_reference<_Tp>::value, "'std::" _Container "' cannot hold references"); \ | ||
| static_assert(!is_function<_Tp>::value, "'std::" _Container "' cannot hold functions"); \ | ||
| static_assert( \ | ||
| !__libcpp_is_unbounded_array<_Tp>::value, "'std::" _Container "' cannot hold C arrays of an unknown size") \ | ||
| _LIBCPP_CHECK_CONTAINER_VALUE_TYPE_IS_NOT_ARRAY_BEFORE_CXX20(_Container, _Tp) | ||
|
|
||
| #define _LIBCPP_CHECK_CONTAINER_VALUE_TYPE_REQUIREMENTS_FULL(_Container, _Tp) \ | ||
| _LIBCPP_CHECK_CONTAINER_VALUE_TYPE_REQUIREMENTS_BASE(_Container, _Tp); \ | ||
| static_assert(!is_void<_Tp>::value, "'std::" _Container "' cannot hold 'void'") | ||
|
|
||
| #endif // _LIBCPP___TYPE_TRAITS_DIAGNOSTIC_UTILITIES_H | ||
Uh oh!
There was an error while loading. Please reload this page.