Commit Graph

957 Commits

Author SHA1 Message Date
dmitrykobets-msft
78eb6ca145
Document span_ext (#1098)
`<gsl/span>` is intended to mirror `<span>` in the STL. `<span_ext>` provides convenience features that aren't part of `<span>`.
Address #1095
2023-02-23 10:22:02 -08:00
Werner Henze
7f7108a076
Better links to CoreGuidelines (#1094)
The `#i13-do-not-pass-an-array-as-a-single-pointer` anchor seems to be auto generated based on the title of the section. The `#Ri-array` anchor is explicitely written in the source, so this should be a better link.
2023-02-21 17:11:30 -08:00
Werner Henze
7a297d4283
Extend docs and tests for span ctor (#1096) 2023-02-21 15:46:40 -08:00
Werner Henze
9851b94d7e
add some span test for constructor from other span (#1093)
More combinations with dynamic_extent or fixed extent for higher coverage.
2023-02-17 13:05:40 -08:00
Werner Henze
743939744c
Documentation (#1086)
Add documentation for #1071.
2023-02-17 10:38:34 -08:00
Werner Henze
3ba80d5dd4
simplify to_byte (#1090)
- to_byte_impl is not necessary, the same can be achieved with shorter code
- add test code for things that should not compile
2023-02-14 14:10:56 -08:00
Werner Henze
49c88f27bd
add not_null and strict_not_null tests for const (#1085) 2023-02-06 13:16:06 -08:00
jpr42
f7da2e41f0
Raise CMake min to 3.14 (#1083)
- Explicitly test package manager support with CMake 3.14 and Ninja
- Remove gsl_install.cmake
- Simplify installation code
2023-02-06 11:16:37 -08:00
dmitrykobets-msft
cbf5e664fc
Fix max macro collision (#1081)
PR https://github.com/microsoft/GSL/pull/1076 introduced a usage of `numeric_limits::max()` function, which seems to have [issues interacting with some Windows headers](https://github.com/skypjack/entt/wiki/Frequently-Asked-Questions#warning-c4003-the-min-the-max-and-the-macro). This PR implements [a simple fix](https://stackoverflow.com/questions/1394132/macro-and-member-function-conflict), which is to wrap the invocations in parentheses. This offloads the fix from the users of the library.
2023-01-19 13:17:39 -08:00
Werner Henze
a381a3759f
1075 Wrong Expects in gsl::at? (#1076)
https://github.com/microsoft/GSL/issues/1075
- Add `static_assert` because we only support C style array `at` for up to half of the address space.
- Add `std::` before `size_t`.
- tests:
  - Add `#include <exception>`
  - Implement `span_tests` `interop_with_gsl_at` like `at_tests` `std_span`
2023-01-18 13:33:20 -08:00
Gabriel Gerlero
0822838a7c
Add Linguist language override for include files (#1079)
Add a `linguist-language` Git attribute that matches the files at `include/gsl` and sets their language to C++. Without this override, these files are not detected as C++ code by [GitHub's Linguist](https://github.com/github/linguist) (likely due to lacking any file extensions).

This will cause GitHub.com to count these files correctly as C++ code and do syntax highlighting when browsing the repo.

**Linguist breakdown results**

Before:

<details>


```
$ docker run --rm -v $(pwd):$(pwd) -w $(pwd) -t linguist github-linguist --breakdown
91.57%  152148     C++
8.43%   14011      CMake

CMake:
CMakeLists.txt
cmake/gsl_functions.cmake
cmake/gsl_install.cmake
include/CMakeLists.txt
tests/CMakeLists.txt

C++:
tests/algorithm_tests.cpp
tests/assertion_tests.cpp
tests/at_tests.cpp
tests/byte_tests.cpp
tests/deathTestCommon.h
tests/no_exception_ensure_tests.cpp
tests/notnull_tests.cpp
tests/owner_tests.cpp
tests/span_compatibility_tests.cpp
tests/span_ext_tests.cpp
tests/span_tests.cpp
tests/strict_notnull_tests.cpp
tests/utils_tests.cpp
```

</details>

After:

<details>

```
$ docker run --rm -v $(pwd):$(pwd) -w $(pwd) -t linguist github-linguist --breakdown
94.16%  225699     C++
5.84%   14011      CMake

CMake:
CMakeLists.txt
cmake/gsl_functions.cmake
cmake/gsl_install.cmake
include/CMakeLists.txt
tests/CMakeLists.txt

C++:
include/gsl/algorithm
include/gsl/assert
include/gsl/byte
include/gsl/gsl
include/gsl/gsl_algorithm
include/gsl/gsl_assert
include/gsl/gsl_byte
include/gsl/gsl_narrow
include/gsl/gsl_util
include/gsl/narrow
include/gsl/pointers
include/gsl/span
include/gsl/span_ext
include/gsl/string_span
include/gsl/util
tests/algorithm_tests.cpp
tests/assertion_tests.cpp
tests/at_tests.cpp
tests/byte_tests.cpp
tests/deathTestCommon.h
tests/no_exception_ensure_tests.cpp
tests/notnull_tests.cpp
tests/owner_tests.cpp
tests/span_compatibility_tests.cpp
tests/span_ext_tests.cpp
tests/span_tests.cpp
tests/strict_notnull_tests.cpp
tests/utils_tests.cpp
```
</details>
2023-01-06 08:11:06 -08:00
Werner Henze
f94c1f6f2b
use code spans in README.md (#1078) 2022-12-29 10:23:30 -08:00
Werner Henze
ac26d7bc71
cleanup natvis (#1077)
- `fail_fast`,`basic_string_span` and `basic_zstring_span` are not declared in the headers any more.
- Name the exporting header file for all types in `GSL.natvis`.
2022-12-29 10:21:11 -08:00
Werner Henze
c016bdc77f
remove all deprecated string_span stuff (#1074)
This solves issue #1070 and removes the class `string_span`. The only content remaining in the header file `gsl/string_span` is the `*zstring` types.
This also removes the `string_span_tests.cpp` unit tests as these were only for the deprecated `string_span` class.

Co-authored-by: Werner Henze <werner.henze+gitcommits@posteo.de>
2022-12-27 07:22:26 -08:00
dmitrykobets-msft
46c72713f2
Document potentially confusing behavior in gsl::narrow (#1073)
NaN != Nan, so the comparisons used in gsl::narrow will always throw when attempting to cast a NaN value. This may be surprising, so document it.
2022-12-24 11:49:26 -08:00
dmitrykobets-msft
6c6111acb7
Remove null check inside not_null::get (#1067)
Guidelines issue 2006 removes the null check inside not_null::get, since the contained pointer is already guaranteed to be not-null upon construction.

Resolves #1051
2022-12-14 18:16:52 -08:00
dmitrykobets-msft
f3620bb009
Suppress false postive warning (#1068)
The Clang compiler for MSVC in Visual Studio 2022 17.4.33122.133 used by the test runner has a bug which raises -Wdeprecated "out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated" in gsl/span, when compiling with C++14. Temporarily suppress this warning for MSVC Clang with C++14.
2022-12-14 15:39:34 -08:00
Changming Sun
517ed29228
Fix GSL_SUPPRESS definition when nvcc is in-use (#1064) 2022-11-07 14:00:32 -08:00
jpr42
d69e578519
clang-tidy: performance-noexcept-move-constructor (#1063)
I ran GSL through clang-tidy with the performance-* checks

https://releases.llvm.org/15.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/performance/noexcept-move-constructor.html
2022-11-01 10:07:47 -07:00
jpr42
9c4212aca4
Raise CMake min to 3.8 (#1061)
This avoids propagating -std=c++14 as a compile option

Currently if you use less than CMake 3.8 and you install the project
`-std=c++14` gets added to the INTERFACE_COMPILE_OPTIONS. This forces
users to use C++ 14 or remove the property from the imported target.

The solution is to raise the minimum and use `cxx_std_14`
2022-10-29 12:31:23 -07:00
Eli Boyarski
1e0d0446dd
README.md: fixed a typo (#1062) 2022-10-24 13:34:44 -07:00
jpr42
c52bad36aa
CMake cleanup (#1060)
- Move all install logic inside gsl_install.cmake
  - This makes reading the logic easier, and avoids the enable language
    issue with `GNUInstallDirs` by having it included after the project
    call
- Have all functions inside gsl_functions.cmake
- Use CMake idiom PROJECT_IS_TOP_LEVEL
- Update README.md
2022-10-18 11:05:09 -07:00
dmitrykobets-msft
991fa6682e
Prevent inefficient copying when using not_null::get (#1059)
Closes issue #550, which highlighted overhead in not_null::get for larger types such as shared_ptr. Every call to get would return a copy of the contained value.
This PR implements Herb's suggestion for changing the return type of not_null::get. The not_null's value will now only be copied if it is "trivially copyable"; otherwise, it will be returned by const reference.
Note: this change also forces the returned copy to be const.
2022-10-11 16:49:16 -07:00
Herb Sutter
7d49d4b45d
Clean up final_act and finally, closes #846 (#977)
Somewhere along the way, GSL's implementation of final_act and finally seems to have become way overthought. This PR is to re-simplify these facilities back to what C++ Core Guidelines C.30 said which is simple and clear and works. It just copies the invocable thing, and doesn't bother trying to optimize the copy. This should be fine, because we're typically passing something that's cheap to copy, often a stateless lambda.

The problem in #846 appears to be because finally looks like was originally written as a const&/&& overload (its state at the time that issue was opened)... to eliminate a copy when you invoke it with a temporary. If so, then the && was probably never intended to be a forwarder, but an rvalue reference that tripped over the horrid C++ syntax collision where a && parameter magically instead means a forwarding reference because the type happens to be a template parameter type here. So I suspect the original author was just trying to write an rvalue overload, and the forwarder that's there now was never intended at all.
2022-10-10 16:09:21 -07:00
Rose
849f7ceaf7
Fix Clang-tidy 15 warnings (#1058)
These warnings were found by running clang-tidy 15.
2022-10-06 09:44:39 -07:00
dmitrykobets-msft
1683d87a3f
Fix NDK version in Android CI (#1054)
This PR future-proofs the fix made in #1053, which is now outdated due to further updates to the NDK version in the Azure VMs used as part of the CI.
2022-09-27 17:04:21 -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
dmitrykobets-msft
c412deb31e
Update compiler support (#1019) 2021-12-10 11:17:47 -08:00
dmitrykobets-msft
bcf008ae55
Fix/implement C++2020 compilation, tests, and CI (#1017)
* Fix C++20 bugs and tests
* Rework CI for C++2020 tests
* Update readme compiler versions
2021-12-09 14:54:06 -08:00
dmitrykobets-msft
e0880931ae
Fix googletest build failure with gcc 11.1+ (#1015) 2021-11-17 12:24:40 -08:00
Jordan Maples
c31a9ad5e8
Delete .travis.yml (#995) 2021-10-26 16:52:07 -07:00
Werner Henze
da80ce15d8
make zstring family don't require empty angle brackets any more (#998)
Co-authored-by: Werner Henze <werner.henze+gitcommits@posteo.de>
2021-10-26 16:50:58 -07:00
Jean-Michaël Celerier
f09b24970d
Fix gsl/util for c++20 compilers without <span> (#993)
For instance, clang 10 sets __cplusplus >= 202002L yet does not have span, which causes build errors:

https://gcc.godbolt.org/z/Yq345zGea
2021-09-15 15:12:11 -07:00
Johel Ernesto Guerrero Peña
8a4b9ed0bf
feat: narrow for non totally ordered types (#986) 2021-06-23 15:28:45 -07:00
Jordan Maples [MSFT]
b26f6d5ec7
gsl::at behavior change regarding gsl::span (#985)
* move span specialization of 'at' to <gsl/span> and update the parameter to be taken by reference

* undid previous changes and acted upon decisions made in maintainer sync. Fixed tests failing in /kernel mode

* ran clang-format on the include folder

* ran clang-format on the test folder

Co-authored-by: Jordan Maples <jordan.maples@microsoft.com>
2021-05-20 18:18:08 -07:00
Tushar Maheshwari
c1cbb41b42
Fix iPhone simulator CI (#981)
* Run iOS simulator CI

* Fix link errors

- scope function linkage using anonymous namespace

* Update noexcept test for consistency
2021-05-13 10:52:09 -07:00