Skip to content
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

Use _STL_INTERNAL_STATIC_ASSERT(false) when appropriate #4624

Merged
merged 10 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ __declspec(noalias) void _Reverse_copy_vectorized(const void* _First, const void
} else if constexpr (_Nx == 8) {
::__std_reverse_copy_trivially_copyable_8(_First, _Last, _Dest);
} else {
static_assert(false, "Unexpected size");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected size
}
}

Expand All @@ -120,7 +120,7 @@ pair<_Ty*, _Ty*> _Minmax_element_vectorized(_Ty* const _First, _Ty* const _Last)
} else if constexpr (sizeof(_Ty) == 8) {
_Res = ::__std_minmax_element_8(_First, _Last, _Signed);
} else {
static_assert(false, "Unexpected size");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected size
}

return {const_cast<_Ty*>(static_cast<const _Ty*>(_Res._Min)), const_cast<_Ty*>(static_cast<const _Ty*>(_Res._Max))};
Expand Down Expand Up @@ -166,7 +166,7 @@ auto _Minmax_vectorized(_Ty* const _First, _Ty* const _Last) noexcept {
return ::__std_minmax_8u(_First, _Last);
}
} else {
static_assert(false, "Unexpected size");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected size
}
}

Expand All @@ -193,7 +193,7 @@ _Ty* _Find_last_vectorized(_Ty* const _First, _Ty* const _Last, const _TVal _Val
return const_cast<_Ty*>(
static_cast<const _Ty*>(::__std_find_last_trivial_8(_First, _Last, static_cast<uint64_t>(_Val))));
} else {
static_assert(false, "Unexpected size");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected size
}
}

Expand All @@ -213,7 +213,7 @@ _Ty1* _Find_first_of_vectorized(
return const_cast<_Ty1*>(
static_cast<const _Ty1*>(::__std_find_first_of_trivial_8(_First1, _Last1, _First2, _Last2)));
} else {
static_assert(false, "Unexpected size");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected size
}
}

Expand All @@ -231,7 +231,7 @@ __declspec(noalias) void _Replace_vectorized(
} else if constexpr (sizeof(_Ty) == 8) {
::__std_replace_8(_First, _Last, static_cast<uint64_t>(_Old_val), static_cast<uint64_t>(_New_val));
} else {
static_assert(false, "Unexpected size");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected size
}
}

Expand Down
2 changes: 1 addition & 1 deletion stl/inc/bit
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ _NODISCARD constexpr _Ty byteswap(const _Ty _Val) noexcept {
} else if constexpr (sizeof(_Ty) == 8) {
return static_cast<_Ty>(_Byteswap_uint64(static_cast<unsigned long long>(_Val)));
} else {
static_assert(false, "Unexpected integer size");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected size
}
}
#endif // _HAS_CXX23
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -3037,7 +3037,7 @@ namespace chrono {
static_assert(false, "A three-step clock time conversion is required to be unique, "
"either utc-to-system or system-to-utc, but not both (N4950 [time.clock.cast.fn]/2).");
} else {
static_assert(false, "should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}

Expand Down Expand Up @@ -5387,7 +5387,7 @@ namespace chrono {
} else if constexpr (_Is_specialization_v<_Ty, _Local_time_format_t>) {
return _Type == 'z' || _Type == 'Z' || _Is_valid_type<decltype(_Ty::_Time)>(_Type);
} else {
static_assert(false, "should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected type
}
}

Expand Down
12 changes: 6 additions & 6 deletions stl/inc/compare
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ namespace _Strong_order {
} else if constexpr (_Strat == _St::_Three) {
return static_cast<strong_ordering>(compare_three_way{}(_Left, _Right));
} else {
static_assert(false, "should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down Expand Up @@ -579,7 +579,7 @@ namespace _Weak_order {
return static_cast<weak_ordering>(
static_cast<strong_ordering>(strong_order(_Left, _Right))); // intentional ADL
} else {
static_assert(false, "should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down Expand Up @@ -664,7 +664,7 @@ namespace _Partial_order {
return static_cast<partial_ordering>(
static_cast<strong_ordering>(strong_order(_Left, _Right))); // intentional ADL
} else {
static_assert(false, "should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down Expand Up @@ -720,7 +720,7 @@ namespace _Compare_strong_order_fallback {
: _Left < _Right ? strong_ordering::less
: strong_ordering::greater;
} else {
static_assert(false, "should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down Expand Up @@ -770,7 +770,7 @@ namespace _Compare_weak_order_fallback {
: _Left < _Right ? weak_ordering::less
: weak_ordering::greater;
} else {
static_assert(false, "should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down Expand Up @@ -829,7 +829,7 @@ namespace _Compare_partial_order_fallback {
: _Right < _Left ? partial_ordering::greater
: partial_ordering::unordered;
} else {
static_assert(false, "should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/functional
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,7 @@ public:
} else if constexpr (_Del == _Deletion_kind::_Normal_array) {
delete[] _Ptr;
} else {
static_assert(false, "Unknown _Deletion_kind.");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ namespace ranges {
} else if constexpr (_Strat == _St::_Own) {
return owning_view{_STD forward<_Rng>(_Range)};
} else {
static_assert(false, "Should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down Expand Up @@ -2164,7 +2164,7 @@ namespace ranges {
} else if constexpr (_Strat == _St::_As_rvalue) {
return as_rvalue_view{_STD forward<_Rng>(_Range)};
} else {
static_assert(false, "Should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down Expand Up @@ -3142,7 +3142,7 @@ namespace ranges {
} else if constexpr (_Strat == _St::_Reconstruct_subrange) {
return subrange(_First, _First + _Count);
} else {
static_assert(false, "Should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
}
Expand Down Expand Up @@ -3548,7 +3548,7 @@ namespace ranges {
} else if constexpr (_Strat == _St::_Reconstruct_other) {
return remove_cvref_t<_Rng>(_RANGES begin(_Range) + _Count, _RANGES end(_Range));
} else {
static_assert(false, "Should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
}
Expand Down Expand Up @@ -5389,7 +5389,7 @@ namespace ranges {
} else if constexpr (_Strat == _St::_Common) {
return common_view{_STD forward<_Rng>(_Range)};
} else {
static_assert(false, "Should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down Expand Up @@ -5548,7 +5548,7 @@ namespace ranges {
} else if constexpr (_Strat == _St::_Reverse) {
return reverse_view{_STD forward<_Rng>(_Range)};
} else {
static_assert(false, "Should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down Expand Up @@ -5692,7 +5692,7 @@ namespace ranges {
} else if constexpr (_Strat == _St::_As_const) {
return as_const_view{_STD forward<_Rng>(_Range)};
} else {
static_assert(false, "Should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
}
}
};
Expand Down
16 changes: 8 additions & 8 deletions stl/inc/tuple
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ _NODISCARD constexpr _Ty& get(tuple<_Types...>& _Tuple) noexcept {
using _Ttype = typename tuple_element<_Idx, tuple<_Types...>>::_Ttype;
return static_cast<_Ttype&>(_Tuple)._Myfirst._Val;
} else {
static_assert(
false, "get<T>(tuple<Types...>&) requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)");
static_assert(false, "get<T>(tuple<Types...>&) "
"requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)");
}
}

Expand All @@ -966,8 +966,8 @@ _NODISCARD constexpr const _Ty& get(const tuple<_Types...>& _Tuple) noexcept {
using _Ttype = typename tuple_element<_Idx, tuple<_Types...>>::_Ttype;
return static_cast<const _Ttype&>(_Tuple)._Myfirst._Val;
} else {
static_assert(
false, "get<T>(const tuple<Types...>&) requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)");
static_assert(false, "get<T>(const tuple<Types...>&) "
"requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)");
}
}

Expand All @@ -978,8 +978,8 @@ _NODISCARD constexpr _Ty&& get(tuple<_Types...>&& _Tuple) noexcept {
using _Ttype = typename tuple_element<_Idx, tuple<_Types...>>::_Ttype;
return static_cast<_Ty&&>(static_cast<_Ttype&>(_Tuple)._Myfirst._Val);
} else {
static_assert(
false, "get<T>(tuple<Types...>&&) requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)");
static_assert(false, "get<T>(tuple<Types...>&&) "
"requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)");
}
}

Expand All @@ -990,8 +990,8 @@ _NODISCARD constexpr const _Ty&& get(const tuple<_Types...>&& _Tuple) noexcept {
using _Ttype = typename tuple_element<_Idx, tuple<_Types...>>::_Ttype;
return static_cast<const _Ty&&>(static_cast<const _Ttype&>(_Tuple)._Myfirst._Val);
} else {
static_assert(
false, "get<T>(const tuple<Types...>&&) requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)");
static_assert(false, "get<T>(const tuple<Types...>&&) "
"requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)");
}
}

Expand Down
16 changes: 8 additions & 8 deletions stl/inc/variant
Original file line number Diff line number Diff line change
Expand Up @@ -1196,8 +1196,8 @@ _NODISCARD constexpr decltype(auto) get(variant<_Types...>& _Var) {
if constexpr (_Idx < sizeof...(_Types)) {
return _STD get<_Idx>(_Var);
} else {
static_assert(
false, "get<T>(variant<Types...>&) requires T to occur exactly once in Types. (N4971 [variant.get]/8)");
static_assert(false, "get<T>(variant<Types...>&) "
"requires T to occur exactly once in Types. (N4971 [variant.get]/8)");
}
}
_EXPORT_STD template <class _Ty, class... _Types>
Expand All @@ -1207,8 +1207,8 @@ _NODISCARD constexpr decltype(auto) get(variant<_Types...>&& _Var) {
if constexpr (_Idx < sizeof...(_Types)) {
return _STD get<_Idx>(_STD move(_Var));
} else {
static_assert(
false, "get<T>(variant<Types...>&&) requires T to occur exactly once in Types. (N4971 [variant.get]/8)");
static_assert(false, "get<T>(variant<Types...>&&) "
"requires T to occur exactly once in Types. (N4971 [variant.get]/8)");
}
}
_EXPORT_STD template <class _Ty, class... _Types>
Expand All @@ -1218,8 +1218,8 @@ _NODISCARD constexpr decltype(auto) get(const variant<_Types...>& _Var) {
if constexpr (_Idx < sizeof...(_Types)) {
return _STD get<_Idx>(_Var);
} else {
static_assert(false,
"get<T>(const variant<Types...>&) requires T to occur exactly once in Types. (N4971 [variant.get]/8)");
static_assert(false, "get<T>(const variant<Types...>&) "
"requires T to occur exactly once in Types. (N4971 [variant.get]/8)");
}
}
_EXPORT_STD template <class _Ty, class... _Types>
Expand All @@ -1229,8 +1229,8 @@ _NODISCARD constexpr decltype(auto) get(const variant<_Types...>&& _Var) {
if constexpr (_Idx < sizeof...(_Types)) {
return _STD get<_Idx>(_STD move(_Var));
} else {
static_assert(false,
"get<T>(const variant<Types...>&&) requires T to occur exactly once in Types. (N4971 [variant.get]/8)");
static_assert(false, "get<T>(const variant<Types...>&&) "
"requires T to occur exactly once in Types. (N4971 [variant.get]/8)");
}
}

Expand Down
2 changes: 1 addition & 1 deletion stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,7 @@ private:
} else if constexpr (sizeof...(_Val) == 2) {
_My_data._Mylast = _STD _Uninitialized_copy(_STD forward<_Valty>(_Val)..., _My_data._Myfirst, _Al);
} else {
static_assert(false, "Should be unreachable");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected number of arguments
}
_ASAN_VECTOR_CREATE;
_Guard._Target = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/xlocnum
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ int _Float_put_desired_precision(const streamsize _Precision, const ios_base::fm
} else if constexpr (is_same_v<_Ty, long double>) {
return ((LDBL_MANT_DIG - 1) + 3) / 4;
} else {
static_assert(false, "Expected only double or long double here (not float).");
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected type; shouldn't be float
}
}

Expand Down
8 changes: 5 additions & 3 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -2297,7 +2297,8 @@ _EXPORT_STD template <class _Ty, class _Alloc, class... _Types, enable_if_t<!_Is
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, _Types&&... _Args) noexcept {
if constexpr (!uses_allocator_v<remove_cv_t<_Ty>, _Alloc>) {
static_assert(is_constructible_v<_Ty, _Types...>,
"If uses_allocator_v<remove_cv_t<T>, Alloc> does not hold, T must be constructible from Types...");
"If uses_allocator_v<remove_cv_t<T>, Alloc> is false, "
"T must be constructible from (Types...). (N4981 [allocator.uses.construction]/5)");
(void) _Al;
return _STD forward_as_tuple(_STD forward<_Types>(_Args)...);
} else if constexpr (is_constructible_v<_Ty, allocator_arg_t, const _Alloc&, _Types...>) {
Expand All @@ -2306,8 +2307,9 @@ _NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, _T
} else if constexpr (is_constructible_v<_Ty, _Types..., const _Alloc&>) {
return _STD forward_as_tuple(_STD forward<_Types>(_Args)..., _Al);
} else {
static_assert(false, "T must be constructible from either (allocator_arg_t, const Alloc&, Types...) "
"or (Types..., const Alloc&) if uses_allocator_v<remove_cv_t<T>, Alloc> is true");
static_assert(false, "If uses_allocator_v<remove_cv_t<T>, Alloc> is true, "
"T must be constructible from either (allocator_arg_t, const Alloc&, Types...) "
"or (Types..., const Alloc&). (N4981 [allocator.uses.construction]/5)");
}
}

Expand Down
Loading