Skip to content

Commit

Permalink
Defend sequence container constructors from bad CTAD (#4254)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej authored Dec 14, 2023
1 parent c293fe7 commit ca641a0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions stl/inc/deque
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,9 @@ public:
_Construct_n(_Count, _Val);
}

#if _HAS_CXX17
template <class _Alloc2 = _Alloc, enable_if_t<_Is_allocator<_Alloc2>::value, int> = 0>
#endif // _HAS_CXX17
deque(_CRT_GUARDOVERFLOW size_type _Count, const _Ty& _Val, const _Alloc& _Al)
: _Mypair(_One_then_variadic_args_t{}, _Al) {
_Construct_n(_Count, _Val);
Expand Down
3 changes: 3 additions & 0 deletions stl/inc/forward_list
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ public:
_Insert_op._Attach_after(_Mypair._Myval2._Before_head());
}

#if _HAS_CXX17
template <class _Alloc2 = _Alloc, enable_if_t<_Is_allocator<_Alloc2>::value, int> = 0>
#endif // _HAS_CXX17
forward_list(_CRT_GUARDOVERFLOW size_type _Count, const _Ty& _Val, const _Alloc& _Al)
: _Mypair(_One_then_variadic_args_t{}, _Al) { // construct list from _Count * _Val, allocator
_Flist_insert_after_op2<_Alnode> _Insert_op(_Getal());
Expand Down
3 changes: 3 additions & 0 deletions stl/inc/list
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,9 @@ public:
_Construct_n(_Count, _Val);
}

#if _HAS_CXX17
template <class _Alloc2 = _Alloc, enable_if_t<_Is_allocator<_Alloc2>::value, int> = 0>
#endif // _HAS_CXX17
list(_CRT_GUARDOVERFLOW size_type _Count, const _Ty& _Val, const _Alloc& _Al)
: _Mypair(_One_then_variadic_args_t{}, _Al) { // construct list from _Count * _Val, allocator
_Construct_n(_Count, _Val);
Expand Down
3 changes: 3 additions & 0 deletions stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ public:
_Construct_n(_Count);
}

#if _HAS_CXX17
template <class _Alloc2 = _Alloc, enable_if_t<_Is_allocator<_Alloc2>::value, int> = 0>
#endif // _HAS_CXX17
_CONSTEXPR20 vector(_CRT_GUARDOVERFLOW const size_type _Count, const _Ty& _Val, const _Alloc& _Al = _Alloc())
: _Mypair(_One_then_variadic_args_t{}, _Al) {
_Construct_n(_Count, _Val);
Expand Down
3 changes: 3 additions & 0 deletions stl/inc/xstring
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,9 @@ public:
_Construct<_Construct_strategy::_From_ptr>(_Ptr, _Count);
}

#if _HAS_CXX17
template <class _Alloc2 = _Alloc, enable_if_t<_Is_allocator<_Alloc2>::value, int> = 0>
#endif // _HAS_CXX17
_CONSTEXPR20 basic_string(
_In_reads_(_Count) const _Elem* const _Ptr, _CRT_GUARDOVERFLOW const size_type _Count, const _Alloc& _Al)
: _Mypair(_One_then_variadic_args_t{}, _Al) {
Expand Down
6 changes: 0 additions & 6 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@ std/containers/associative/map/map.cons/deduct_const.pass.cpp FAIL
std/containers/associative/multimap/multimap.cons/deduct.pass.cpp FAIL
std/containers/associative/multimap/multimap.cons/deduct_const.pass.cpp FAIL
std/containers/container.adaptors/priority.queue/priqueue.cons/deduct.pass.cpp FAIL
std/containers/sequences/list/list.cons/deduct.pass.cpp FAIL
std/containers/unord/unord.map/unord.map.cnstr/deduct.pass.cpp FAIL
std/containers/unord/unord.map/unord.map.cnstr/deduct_const.pass.cpp FAIL
std/containers/unord/unord.multimap/unord.multimap.cnstr/deduct.pass.cpp FAIL
Expand Down Expand Up @@ -943,11 +942,6 @@ std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp
# Not analyzed. Error mentions allocator<const T>.
std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp FAIL

# Not analyzed. Looks like deduction guide SFINAE failure.
std/containers/sequences/deque/deque.cons/deduct.pass.cpp FAIL
std/containers/sequences/forwardlist/forwardlist.cons/deduct.pass.cpp FAIL
std/containers/sequences/vector/vector.cons/deduct.pass.cpp FAIL

# Not analyzed. Seems to force a sign conversion error?
std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp SKIPPED

Expand Down

0 comments on commit ca641a0

Please sign in to comment.