mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Suppress warnings on VS (#642)
- gsl::narrow, gsl::narrow_cast and gsl::at are the safe variants suggested by CppCoreGuideline. It does not make sense to let VS warn inside the implementation of these functions that unsafe static_cast is used and that the safe variants shall be used. - Suppress warning that throw_exception can be declared noexcept (for the GSL_TERMINATE_ON_CONTRACT_VIOLATION case)
This commit is contained in:
parent
1f76fbd168
commit
f4a715816c
@ -110,6 +110,10 @@ namespace details
|
||||
#if defined(GSL_TERMINATE_ON_CONTRACT_VIOLATION)
|
||||
|
||||
template <typename Exception>
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#else
|
||||
[[gsl::suppress(f.6)]]
|
||||
#endif
|
||||
[[noreturn]] void throw_exception(Exception&&)
|
||||
{
|
||||
gsl::details::terminate();
|
||||
|
@ -88,6 +88,10 @@ final_action<F> finally(F&& f) noexcept
|
||||
|
||||
// narrow_cast(): a searchable way to do narrowing casts of values
|
||||
template <class T, class U>
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#else
|
||||
[[gsl::suppress(type.1)]]
|
||||
#endif
|
||||
constexpr T narrow_cast(U&& u) noexcept
|
||||
{
|
||||
return static_cast<T>(std::forward<U>(u));
|
||||
@ -108,6 +112,10 @@ namespace details
|
||||
|
||||
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value
|
||||
template <class T, class U>
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#else
|
||||
[[gsl::suppress(type.1)]]
|
||||
#endif
|
||||
T narrow(U u)
|
||||
{
|
||||
T t = narrow_cast<T>(u);
|
||||
@ -121,6 +129,10 @@ T narrow(U u)
|
||||
// at() - Bounds-checked way of accessing builtin arrays, std::array, std::vector
|
||||
//
|
||||
template <class T, std::size_t N>
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#else
|
||||
[[gsl::suppress(type.1,bounds.2,bounds.4)]]
|
||||
#endif
|
||||
constexpr T& at(T (&arr)[N], const index i)
|
||||
{
|
||||
Expects(i >= 0 && i < narrow_cast<index>(N));
|
||||
@ -128,6 +140,10 @@ constexpr T& at(T (&arr)[N], const index i)
|
||||
}
|
||||
|
||||
template <class Cont>
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#else
|
||||
[[gsl::suppress(type.1,bounds.4)]]
|
||||
#endif
|
||||
constexpr auto at(Cont& cont, const index i) -> decltype(cont[cont.size()])
|
||||
{
|
||||
Expects(i >= 0 && i < narrow_cast<index>(cont.size()));
|
||||
|
Loading…
Reference in New Issue
Block a user