Compare commits

..
Author SHA1 Message Date
Vitaly ZaitsevandGitHub a353456718 Fixed wrong version number in exported CMake configs. (#1027) 2022-01-28 15:22:59 -08:00
dmitrykobets-msftandGitHub 99a29ce797 Document safe usage of undefined behavior in gsl::narrow (#1024) 2022-01-26 16:44:07 -08:00
dmitrykobets-msftandGitHub ebf0498363 Update compiler support (#1021)
Bump clang and Xcode supported versions and add support for VS with LLVM
2022-01-06 10:17:21 -08:00
2 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(guidelineSupportLibrary)
project(GSL
VERSION 3.1.0
VERSION 4.0.0
LANGUAGES CXX
)
+6 -1
View File
@@ -36,7 +36,12 @@ GSL_SUPPRESS(f.6) // NO-FORMAT: attribute // TODO: MSVC /analyze does not recogn
constexpr const bool is_different_signedness =
(std::is_signed<T>::value != std::is_signed<U>::value);
const T t = narrow_cast<T>(u);
GSL_SUPPRESS(es.103) // NO-FORMAT: attribute // don't overflow
GSL_SUPPRESS(es.104) // NO-FORMAT: attribute // don't underflow
GSL_SUPPRESS(p.2) // NO-FORMAT: attribute // don't rely on undefined behavior
const T t = narrow_cast<T>(u); // While this is technically undefined behavior in some cases (i.e., if the source value is of floating-point type
// and cannot fit into the destination integral type), the resultant behavior is benign on the platforms
// that we target (i.e., no hardware trap representations are hit).
if (static_cast<U>(t) != u || (is_different_signedness && ((t < T{}) != (u < U{}))))
{