February 1st, 2022

GSL 4.0.0 is Available Now

Dmitry Kobets
Software Engineer

Version 4.0.0 of Microsoft’s implementation of the C++ Core Guidelines Support Library (GSL) is now available for you to download on the releases page. This release maintains the safety guarantees that we have always offered and adds improvements to various parts of the library.

What changed in this release?

Deprecation of gsl::string_span

isocpp/CppCoreGuidelines#1680 removed string_span from the C++ Core Guidelines. The recommendation is to use std::string_view, std::span<char> or gsl::span<char> instead. To more closely align Microsoft’s GSL with the C++ Core Guidelines, we deprecated our implementation of string_span and zstring_span, including basic_string_span, basic_zstring_span, and all related types. For the time being, we will continue to provide the <gsl/string_span> header, but it will not be actively worked on or maintained. A table of all supported and unsupported types/features can be found in the README.md.

Removal of <gsl/multi_span>

multi_span, strided_span, and everything else in <gsl/multi_span> were deprecated over a year ago in GSL 3.0.0, and it is time for them and their associated tests to be removed from the library.

Header files dropped the gsl_ prefix

All headers which previously contained a gsl_ prefix in their name have had this prefix removed. For example, <gsl/gsl_algorithm> is now <gsl/algorithm>. The gsl_ prefixed files still exist and pass through to the updated files, but will be removed in a future release.

Changes to not_null

To more closely align Microsoft’s GSL with the C++ Core Guidelines, gsl::not_null now accepts only types which are comparable to nullptr. Previously, it accepted only types which are assignable from nullptr, but this was stricter than what was intended by the Core Guidelines.

The functions make_not_null and make_strict_not_null, and the not_null comparison operators, are now all noexcept.

gsl::span and std::span now use the correct specialization of gsl::at

gsl::span and std::span now have their own separate specializations of gsl::at, to ensure consistent behavior between the two versions of span. Both overloads are included when importing <gsl/span>. The std::span overload can be separately included from <gsl/util>.

GSL will work in environments where exceptions are disabled, with some caveats

gsl::narrow is the only part of the library which may throw exceptions and has been moved into its own header <gsl/narrow>. This header is included in <gsl/gsl> only if exceptions are enabled. This allows users of the library who are working in environments without exceptions to use all of the other components of the library.

Note: gsl::narrow_cast is still in <gsl/util>, since it does not throw exceptions.

Updated compiler support

The list of supported compilers/toolsets has been updated with newer versions. More info on compiler support can be found in the README.md.

Compiler/Toolset Version
XCode 13.2.1 & 12.5.1
GCC 11.1.0 & 10.3.0
Clang 12.0.0 & 11.0.0
Visual Studio with MSVC VS2022 (17.0) & VS2019 (16.11)
Visual Studio with LLVM VS2022 (17.0) & VS2019 (16.11)

CMake and build improvements

  • GSL Install logic is now guarded by a cmake option GSL_INSTALL: #964
  • Fix bug which prevented the library from being built on a 32-bit host and then being used on a 64-bit machine: #893
  • Build will now use CMAKE_CXX_STANDARD if it’s provided #953
  • Clean up GSL_SUPPRESS warning for intel compilers: #906
  • Fix build failure for C++20 compilers which don’t have std::span: #993
  • Cleaned up some static analysis warnings
  • The cmake cache variable VS_ADD_NATIVE_VISUALIZERS has been renamed to GSL_VS_ADD_NATIVE_VISUALIZERS: #941

Summary

This has been a list of the changes in the GSL 4.0.0 release. You can download the code at the GSL GitHub page. Please stay tuned for future releases!

Author

Dmitry Kobets
Software Engineer

0 comments

Discussion are closed.