Compare commits

...

16 Commits

Author SHA1 Message Date
Dmitry Kobets 327415221f Fix NDK version in Android CI 2022-09-26 15:35:42 -07:00
Werner Henze 10df83d292 solve span compile problem with gcc 5.5.0 (#1052)
GCC 4.8.0 - 7.0 has a bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480) involving specialization in a namespace enclosing the specialized template. This PR fixes an appearance of this bug in the span header.
2022-08-18 12:28:11 -07:00
dmitrykobets-msft 2e94541fcf Use updated NDK version in android test suite (#1053)
https://github.com/actions/runner-images/issues/5930 recently updated the NDK version, resulting in test breakages. Update the version.
2022-08-17 12:40:45 -07:00
dmitrykobets-msft 330583f478 Resolve MSVC warning C5260 (#1049)
* Test solution

* Mark dynamic_extent as inline, compiler-version-permitting
2022-07-18 17:42:21 -07:00
microsoft-github-policy-service[bot] d9fc52e20e Microsoft mandatory file (#1047)
Co-authored-by: microsoft-github-policy-service[bot] <77245923+microsoft-github-policy-service[bot]@users.noreply.github.com>
2022-05-23 15:27:04 -07:00
dmitrykobets-msft da01eb28db Remove useless runtime checks in span implementation (#1029)
Both checks for Expects(ExtentType::size() != dynamic_extent); in storage_type are always useless. storage_type<ExtentType> is only ever created with ExtentType == extent_type<Extent>, where Extent has type std::size_t and is the extent of the span.

Looking at extent_type<std::size_t Ext>::size():

- if Ext != dynamic_extent, then size() always returns Ext, and therefore size() != dynamic_extent
- if Ext == dynamic_extent, then size() returns extent_type<dynamic_extent>::size_. size_ can only be set via one of two constructors:
  - constexpr explicit extent_type(size_type size), which already does the check in question
  - constexpr explicit extent_type(extent_type<Other> ext) : size_(ext.size()), which simply relies on the other extent's size() method
So there is no way for ExtentType::size() == dynamic_extent.
2022-04-28 14:58:25 -07:00
dmitrykobets-msft d8c493c89f Suppress es.46 warning in implementation of gsl::narrow (#1046)
As per the CoreGuidelines, gsl::narrow is defined in terms of static_cast.
Suppress es.46, which suggests converting the static_cast into gsl::narrow
2022-04-28 09:49:38 -07:00
dmitrykobets-msft 7fefaaf2c8 Fix reason for including assert inside gsl/narrow (#1045) 2022-04-28 09:49:10 -07:00
Juan Carlos Arevalo Baeza f21f29d210 gsl/narrow should include <exception> (#1044)
This file uses std::exception, so it should include the appropriate header.

Normally it gets the STL's <exception> header included via the gsl/assert file, but this is skipped with _HAS_EXCEPTIONS=0. I understand _HAS_EXCEPTIONS is undocumented and unsupported, but regardless, the appropriate header should be included here.

Alternatively, gsl/narrow should be modified to support _HAS_EXCEPTIONS=0, like gsl/assert was. But I'm not proposing that change. <exception> does define std::exception even with _HAS_EXCEPTIONS=0.
2022-04-26 14:41:10 -07:00
dmitrykobets-msft 2bfd495080 Suppress -Wfloat-equal warning in implementation of gsl::narrow (#1043)
In the implementation of gsl::narrow, there is a comparison `static_cast<U>(t) != u` which may be comparing two floats.
The comparison here is done purposefully to categorize ill effects of narrowing conversion, since the values being compared *should* be the same when compared with `operator==`. 
Note, using #pragma GCC will suppress this warning for both GCC and Clang.
2022-04-14 11:08:28 -07:00
dmitrykobets-msft 383723676c Make gsl::span's iterators use the contiguous_iterator concept (#1035)
Resolves #1016

Co-authored-by: Casey Carter <Casey@Carter.net>
2022-03-22 13:20:54 -07:00
dmitrykobets-msft f22f524aa2 Suppress reserved identifier warning (#1041)
The following reserved identifiers are being used specifically to target certain MSVC constructs, so suppress the warning in VS 2022 (LLVM) "... is reserved because it starts with '_' followed by a capital letter":
- _Unchecked_type
- _Verify_range
- _Verify_offset
- _Unwrapped
- _Unwrap_when_unverified
- _Seek_to
- _Unchecked_begin
- _Unchecked_end
2022-03-22 12:24:23 -07:00
Werner Henze 4377f6e603 quoted form of #include when GSL includes GSL files (#1030)
[SF.12: Prefer the quoted form of #include for files relative to the including file and the angle bracket form everywhere else](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rs-incform)

Additionally changed #include order in `span` so that all `span_ext` is in the GSL include block and not in the STL include block.

Fixes issues #1025.

Co-authored-by: Werner Henze <w.henze@avm.de>
2022-01-31 13:06:42 -08:00
Vitaly Zaitsev a353456718 Fixed wrong version number in exported CMake configs. (#1027) 2022-01-28 15:22:59 -08:00
dmitrykobets-msft 99a29ce797 Document safe usage of undefined behavior in gsl::narrow (#1024) 2022-01-26 16:44:07 -08:00
dmitrykobets-msft 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
22 changed files with 188 additions and 67 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ jobs:
echo "Emulator starting"
- name: Configure
run: cmake -Werror=dev -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=16 -DANDROID_ABI=x86_64 -DCMAKE_BUILD_TYPE=Debug ..
run: cmake -Werror=dev -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_LATEST_HOME/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=16 -DANDROID_ABI=x86_64 -DCMAKE_BUILD_TYPE=Debug ..
- name: Build
run: cmake --build . --parallel
+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
)
+10 -6
View File
@@ -93,13 +93,17 @@ Below is a table showing the versions currently being tested.
Compiler |Toolset Versions Currently Tested
:------- |--:
XCode | 13.1 & 12.5.1
GCC | 11.1.0 & 10.3.0
Clang | 11.0.0 & 10.0.0
Visual Studio with MSVC | VS2019 (16.11) & VS2022 (17.0)
Visual Studio with LLVM | VS2019 (16.11)
XCode | 13.2.1 & 12.5.1
GCC | 11[^1] & 10[^2]
Clang | 12[^2] & 11[^2]
Visual Studio with MSVC | VS2022[^3] & VS2019[^4]
Visual Studio with LLVM | VS2022[^3] & VS2019[^4]
- Support for Visual Studio 2022 with LLVM will be added in the near future
[^1]: Precise version may be found in the [latest CI results](https://dev.azure.com/cppstat/GSL/_build?definitionId=1&branchFilter=26).
[^2]: Precise version may be found in the [latest CI results](https://dev.azure.com/cppstat/GSL/_build?definitionId=1&branchFilter=26). Should be the version specified [here](https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md#language-and-runtime).
[^3]: Precise version may be found in the [latest CI results](https://dev.azure.com/cppstat/GSL/_build?definitionId=1&branchFilter=26). Should be the version specified [here](https://github.com/actions/virtual-environments/blob/main/images/win/Windows2022-Readme.md#visual-studio-enterprise-2022).
[^4]: Precise version may be found in the [latest CI results](https://dev.azure.com/cppstat/GSL/_build?definitionId=1&branchFilter=26). Should be the version specified [here](https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#visual-studio-enterprise-2019).
---
If you successfully port GSL to another platform, we would love to hear from you!
+41
View File
@@ -0,0 +1,41 @@
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.7 BLOCK -->
## Security
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
## Reporting Security Issues
**Please do not report security vulnerabilities through public GitHub issues.**
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
## Preferred Languages
We prefer all communications to be in English.
## Policy
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
<!-- END MICROSOFT SECURITY.MD BLOCK -->
+14 -19
View File
@@ -22,7 +22,7 @@ stages:
parameters:
compiler: clang
image: ubuntu-20.04
compilerVersions: [ 11, 10 ]
compilerVersions: [ 12, 11 ]
setupfile: 'setup_clang.yml'
- stage: Xcode
@@ -32,7 +32,7 @@ stages:
parameters:
compiler: 'Xcode'
image: macOS-11
compilerVersions: [ '12.5.1', '13.1' ]
compilerVersions: [ '12.5.1', '13.2.1' ]
setupfile: 'setup_apple.yml'
- stage: VS_MSVC
@@ -40,13 +40,13 @@ stages:
jobs:
- template: ./pipelines/jobs.yml
parameters:
compiler: 'VS2019 (16.11)'
compilerVersions: [ 'MSVC' ]
compiler: 'VS2019 (MSVC)'
compilerVersions: [ 'default' ]
image: windows-2019
- template: ./pipelines/jobs.yml
parameters:
compiler: 'VS2022 (17.0)'
compilerVersions: [ 'MSVC' ]
compiler: 'VS2022 (MSVC)'
compilerVersions: [ 'default' ]
image: windows-2022
- stage: VS_LLVM
@@ -54,18 +54,13 @@ stages:
jobs:
- template: ./pipelines/jobs.yml
parameters:
compiler: 'VS2019 (16.11)'
compilerVersions: [ 'LLVM' ]
compiler: 'VS2019 (LLVM)'
compilerVersions: [ 'default' ]
image: windows-2019
extraCmakeArgs: '-T ClangCL'
# The *same* config as with 2019 but on 2022 yields an error.
# Tracking issue: https://github.com/actions/virtual-environments/issues/4716
# - template: ./pipelines/jobs.yml
# parameters:
# compiler: 'VS2022 LLVM'
# compilerVersions: [ '17.0' ]
# image: windows-2022
# extraCmakeArgs: '-T ClangCL'
# CXXVersions: [ 14 ]
# buildTypes: [ Release ]
- template: ./pipelines/jobs.yml
parameters:
compiler: 'VS2022 (LLVM)'
compilerVersions: [ 'default' ]
image: windows-2022
extraCmakeArgs: '-T ClangCL'
+2 -2
View File
@@ -17,8 +17,8 @@
#ifndef GSL_ALGORITHM_H
#define GSL_ALGORITHM_H
#include <gsl/assert> // for Expects
#include <gsl/span> // for dynamic_extent, span
#include "assert" // for Expects
#include "span" // for dynamic_extent, span
#include <algorithm> // for copy_n
#include <cstddef> // for ptrdiff_t
+8 -8
View File
@@ -17,16 +17,16 @@
#ifndef GSL_GSL_H
#define GSL_GSL_H
#include <gsl/algorithm> // copy
#include <gsl/assert> // Ensures/Expects
#include <gsl/byte> // byte
#include <gsl/pointers> // owner, not_null
#include <gsl/span> // span
#include <gsl/string_span> // zstring, string_span, zstring_builder...
#include <gsl/util> // finally()/narrow_cast()...
#include "algorithm" // copy
#include "assert" // Ensures/Expects
#include "byte" // byte
#include "pointers" // owner, not_null
#include "span" // span
#include "string_span" // zstring, string_span, zstring_builder...
#include "util" // finally()/narrow_cast()...
#ifdef __cpp_exceptions
#include <gsl/narrow> // narrow()
#include "narrow" // narrow()
#endif
#endif // GSL_GSL_H
+1 -1
View File
@@ -1,4 +1,4 @@
#pragma once
#pragma message( \
"This header will soon be removed. Use <gsl/algorithm> instead of <gsl/gsl_algorithm>")
#include <gsl/algorithm>
#include "algorithm"
+1 -1
View File
@@ -1,3 +1,3 @@
#pragma once
#pragma message("This header will soon be removed. Use <gsl/assert> instead of <gsl/gsl_assert>")
#include <gsl/assert>
#include "assert"
+1 -1
View File
@@ -1,3 +1,3 @@
#pragma once
#pragma message("This header will soon be removed. Use <gsl/byte> instead of <gsl/gsl_byte>")
#include <gsl/byte>
#include "byte"
+1 -1
View File
@@ -1,3 +1,3 @@
#pragma once
#pragma message("This header will soon be removed. Use <gsl/narrow> instead of <gsl/gsl_narrow>")
#include <gsl/narrow>
#include "narrow"
+1 -1
View File
@@ -1,3 +1,3 @@
#pragma once
#pragma message("This header will soon be removed. Use <gsl/util> instead of <gsl/gsl_util>")
#include <gsl/util>
#include "util"
+20 -3
View File
@@ -16,8 +16,9 @@
#ifndef GSL_NARROW_H
#define GSL_NARROW_H
#include <gsl/assert> // for Expects
#include <gsl/util> // for narrow_cast
#include "assert" // for GSL_SUPPRESS
#include "util" // for narrow_cast
#include <exception> // for std::exception
namespace gsl
{
struct narrowing_error : public std::exception
@@ -30,18 +31,34 @@ template <class T, class U, typename std::enable_if<std::is_arithmetic<T>::value
// clang-format off
GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
GSL_SUPPRESS(f.6) // NO-FORMAT: attribute // TODO: MSVC /analyze does not recognise noexcept(false)
GSL_SUPPRESS(es.46) // NO-FORMAT: attribute // The warning suggests that a floating->unsigned conversion can occur
// in the static_cast below, and that gsl::narrow should be used instead.
// Suppress this warning, since gsl::narrow is defined in terms of
// static_cast
// clang-format on
constexpr T narrow(U u) noexcept(false)
{
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 defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if (static_cast<U>(t) != u || (is_different_signedness && ((t < T{}) != (u < U{}))))
{
throw narrowing_error{};
}
#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
return t;
}
+1 -1
View File
@@ -17,7 +17,7 @@
#ifndef GSL_POINTERS_H
#define GSL_POINTERS_H
#include <gsl/assert> // for Ensures, Expects
#include "assert" // for Ensures, Expects
#include <algorithm> // for forward
#include <cstddef> // for ptrdiff_t, nullptr_t, size_t
+36 -13
View File
@@ -17,15 +17,20 @@
#ifndef GSL_SPAN_H
#define GSL_SPAN_H
#include <gsl/assert> // for Expects
#include <gsl/byte> // for byte
#include <gsl/util> // for narrow_cast
#include "assert" // for Expects
#include "byte" // for byte
#include "span_ext" // for span specialization of gsl::at and other span-related extensions
#include "util" // for narrow_cast
#include <array> // for array
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
#include <gsl/span_ext> // for span specialization of gsl::at and other span-related extensions
#include <iterator> // for reverse_iterator, distance, random_access_...
#include <type_traits> // for enable_if_t, declval, is_convertible, inte...
#include <array> // for array
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
#include <iterator> // for reverse_iterator, distance, random_access_...
#include <memory> // for pointer_traits
#include <type_traits> // for enable_if_t, declval, is_convertible, inte...
#if defined(__has_include) && __has_include(<version>)
#include <version>
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(push)
@@ -110,6 +115,9 @@ namespace details
class span_iterator
{
public:
#if defined(__cpp_lib_ranges) || (defined(_MSVC_STL_VERSION) && defined(__cpp_lib_concepts))
using iterator_concept = std::contiguous_iterator_tag;
#endif // __cpp_lib_ranges
using iterator_category = std::random_access_iterator_tag;
using value_type = std::remove_cv_t<Type>;
using difference_type = std::ptrdiff_t;
@@ -329,8 +337,26 @@ namespace details
pointer begin_ = nullptr;
pointer end_ = nullptr;
pointer current_ = nullptr;
};
template <typename Ptr>
friend struct std::pointer_traits;
};
}} // namespace gsl::details
namespace std
{
template <class Type>
struct pointer_traits<::gsl::details::span_iterator<Type>>
{
using pointer = ::gsl::details::span_iterator<Type>;
using element_type = Type;
using difference_type = ptrdiff_t;
static constexpr element_type* to_address(const pointer i) noexcept { return i.current_; }
};
} // namespace std
namespace gsl { namespace details {
template <std::size_t Ext>
class extent_type
{
@@ -682,14 +708,11 @@ private:
template <class OtherExtentType>
constexpr storage_type(KnownNotNull data, OtherExtentType ext)
: ExtentType(ext), data_(data.p)
{
Expects(ExtentType::size() != dynamic_extent);
}
{}
template <class OtherExtentType>
constexpr storage_type(pointer data, OtherExtentType ext) : ExtentType(ext), data_(data)
{
Expects(ExtentType::size() != dynamic_extent);
Expects(data || ExtentType::size() == 0);
}
+3 -3
View File
@@ -27,8 +27,8 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <gsl/assert> // GSL_KERNEL_MODE
#include <gsl/util> // for narrow_cast, narrow
#include "assert" // GSL_KERNEL_MODE
#include "util" // for narrow_cast, narrow
#include <cstddef> // for ptrdiff_t, size_t
#include <utility>
@@ -41,7 +41,7 @@ namespace gsl
{
// [span.views.constants], constants
constexpr const std::size_t dynamic_extent = narrow_cast<std::size_t>(-1);
GSL_INLINE constexpr const std::size_t dynamic_extent = narrow_cast<std::size_t>(-1);
template <class ElementType, std::size_t Extent = dynamic_extent>
class span;
+3 -3
View File
@@ -17,9 +17,9 @@
#ifndef GSL_STRING_SPAN_H
#define GSL_STRING_SPAN_H
#include <gsl/assert> // for Ensures, Expects
#include <gsl/span_ext> // for operator!=, operator==, dynamic_extent
#include <gsl/util> // for narrow_cast
#include "assert" // for Ensures, Expects
#include "span_ext" // for operator!=, operator==, dynamic_extent
#include "util" // for narrow_cast
#include <algorithm> // for equal, lexicographical_compare
#include <array> // for array
+7 -1
View File
@@ -17,7 +17,7 @@
#ifndef GSL_UTIL_H
#define GSL_UTIL_H
#include <gsl/assert> // for Expects
#include "assert" // for Expects
#include <array>
#include <cstddef> // for ptrdiff_t, size_t
@@ -45,6 +45,12 @@
#define GSL_NODISCARD
#endif // defined(__cplusplus) && (__cplusplus >= 201703L)
#if defined(__cpp_inline_variables)
#define GSL_INLINE inline
#else
#define GSL_INLINE
#endif
namespace gsl
{
//
+1 -1
View File
@@ -3,7 +3,7 @@ parameters:
steps:
- script: |
if [ "${{ parameters.version }}" = "12.5.1" ]; then sudo xcode-select -switch /Applications/Xcode_12.5.1.app; fi
if [ "${{ parameters.version }}" != "default" ]; then sudo xcode-select -switch /Applications/Xcode_${{ parameters.version }}.app; fi
displayName: "Setup Xcode Version"
failOnStderr: true
+13
View File
@@ -62,6 +62,7 @@ if (MSVC AND (GSL_CXX_STANDARD GREATER_EQUAL 17))
set(GSL_CPLUSPLUS_OPT -Zc:__cplusplus -permissive-)
endif()
include(CheckCXXCompilerFlag)
# this interface adds compile options to how the tests are run
# please try to keep entries ordered =)
add_library(gsl_tests_config INTERFACE)
@@ -88,6 +89,7 @@ if(MSVC) # MSVC or simulating MSVC
>
$<$<CXX_COMPILER_ID:Clang>:
-Weverything
-Wfloat-equal
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-covered-switch-default # GTest
@@ -105,6 +107,10 @@ if(MSVC) # MSVC or simulating MSVC
>
>
)
check_cxx_compiler_flag("-Wno-reserved-identifier" WARN_RESERVED_ID)
if (WARN_RESERVED_ID)
target_compile_options(gsl_tests_config INTERFACE "-Wno-reserved-identifier")
endif()
else()
target_compile_options(gsl_tests_config INTERFACE
-fno-strict-aliasing
@@ -117,6 +123,7 @@ else()
-Wpedantic
-Wshadow
-Wsign-conversion
-Wfloat-equal
-Wno-deprecated-declarations # Allow tests for [[deprecated]] elements
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Weverything
@@ -222,12 +229,17 @@ if(MSVC) # MSVC or simulating MSVC
>
$<$<CXX_COMPILER_ID:Clang>:
-Weverything
-Wfloat-equal
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-missing-prototypes
-Wno-unknown-attributes
>
)
check_cxx_compiler_flag("-Wno-reserved-identifier" WARN_RESERVED_ID)
if (WARN_RESERVED_ID)
target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-reserved-identifier")
endif()
else()
target_compile_options(gsl_tests_config_noexcept INTERFACE
-fno-exceptions
@@ -241,6 +253,7 @@ else()
-Wpedantic
-Wshadow
-Wsign-conversion
-Wfloat-equal
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Weverything
-Wno-c++98-compat
+20
View File
@@ -40,6 +40,9 @@
#endif // __has_include(<string_view>)
#endif // __has_include
#endif // (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L))
#if defined(__cplusplus) && __cplusplus >= 202002L
#include <span>
#endif // __cplusplus >= 202002L
#include "deathTestCommon.h"
@@ -1297,3 +1300,20 @@ TEST(span_test, front_back)
EXPECT_DEATH(s2.front(), expected);
EXPECT_DEATH(s2.back(), expected);
}
#if defined(FORCE_STD_SPAN_TESTS) || defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
TEST(span_test, std_span)
{
// make sure std::span can be constructed from gsl::span
int arr[5] = {1, 2, 3, 4, 5};
gsl::span<int> gsl_span{arr};
#if defined(__cpp_lib_ranges) || (defined(_MSVC_STL_VERSION) && defined(__cpp_lib_concepts))
EXPECT_TRUE(std::to_address(gsl_span.begin()) == gsl_span.data());
EXPECT_TRUE(std::to_address(gsl_span.end()) == gsl_span.data() + gsl_span.size());
#endif // __cpp_lib_ranges
std::span<int> std_span = gsl_span;
EXPECT_TRUE(std_span.data() == gsl_span.data());
EXPECT_TRUE(std_span.size() == gsl_span.size());
}
#endif // defined(FORCE_STD_SPAN_TESTS) || defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
+2
View File
@@ -149,5 +149,7 @@ TEST(utils_tests, narrow)
EXPECT_TRUE(
narrow<std::complex<float>>(std::complex<double>(4, 2)) == std::complex<float>(4, 2));
EXPECT_THROW(narrow<std::complex<float>>(std::complex<double>(4.2)), narrowing_error);
EXPECT_TRUE(narrow<int>(float(1)) == 1);
}
#endif // GSL_KERNEL_MODE