Just tagging as 4.2.0 is not enough, the version number must be incremented for cmake and in the readme. Compare https://github.com/microsoft/GSL/pull/1163.
Co-authored-by: Werner Henze <w.henze@avm.de>
- A macro with the very generic name `BYTE_TYPE` is likely to collide with existing code, so get rid of the macro.
- The new solution is to provide a non-deprecated `byte` in the namespace `gsl::impl`.
- Users of GSL should use `gsl::byte`, which is still deprecated when mapped to a `std::std::byte`.
- GSL types and functions need to use `gsl::impl::byte` so they do not trigger the deprecation warning.
- The `gsl::impl::byte` return type in an exported function is not nice, it might mislead users to use that type in their own declarations. But the `BYTE_TYPE` solution is not better in this respect.
Co-authored-by: Werner Henze <w.henze@avm.de>
- reintroduce documentation internal links
- remove `gsl::` prefix in table so it is the same as in the other tables
- fix documentation for span::element_type
Co-authored-by: Werner Henze <w.henze@avm.de>
* deprecated features adopted into C++
1) Mark the following GSL features as deprecated:
- gsl::unique_ptr (always)
- gsl::shared_ptr (always)
- gsl::byte (since c++17)
- gsl::joining_thread (never implemented)
2) Refactor existing deprecations to use the new GSL_DEPRECATED(msg) macro.
3) Create a section in the README for deprecated features in the
standard.
* do not deprecate gsl::to_integer because we never claim to implement it.
* do not use gsl::byte if it is deprecated
Reverts commit that changes #include "assert" -> #include "gsl/assert".
This change is necessary in order to comply with CppCoreGuideline's
SF.12. Now we do #include "./assert".
* Add more gsl::span tests [copilot]
This PR adds comprehensive unit tests for `gsl::span` to ensure its correctness and consistency. The following tests have been added:
1. **Empty Span Tests**:
- Tests to verify the behavior of an empty `gsl::span` and `gsl::span<const int>`.
2. **Conversion Tests**:
- Tests to check the conversion between different types of `gsl::span`.
3. **Comparison Operator Tests**:
- Tests to verify the comparison operators for `gsl::span`.
4. **Deduction Guide Tests**:
- Tests to compare the behavior of `gsl::span` and `std::span` deduction guides for various types of arrays and containers.
These tests help ensure that `gsl::span` behaves correctly in various scenarios and is consistent with `std::span`.
This PR was created with the help of GitHub Copilot.
**Changes**:
- Added tests for empty span.
- Added tests for conversions.
- Added tests for comparison operators.
- Added tests for deduction guides.
**Testing**:
- All new tests have been added to the existing test suite.
- Run the test suite using `ctest` to ensure all tests pass.This PR adds comprehensive unit tests for `gsl::span` to ensure its correctness and consistency. The following tests have been added:
1. **Empty Span Tests**:
- Tests to verify the behavior of an empty `gsl::span` and `gsl::span<const int>`.
2. **Conversion Tests**:
- Tests to check the conversion between different types of `gsl::span`.
3. **Comparison Operator Tests**:
- Tests to verify the comparison operators for `gsl::span`.
4. **Deduction Guide Tests**:
- Tests to compare the behavior of `gsl::span` and `std::span` deduction guides for various types of arrays and containers.
These tests help ensure that `gsl::span` behaves correctly in various scenarios and is consistent with `std::span`.
This PR was created with the help of GitHub Copilot.
**Changes**:
- Added tests for empty span.
- Added tests for conversions.
- Added tests for comparison operators.
- Added tests for deduction guides.
**Testing**:
- All new tests have been added to the existing test suite.
- Run the test suite using `ctest` to ensure all tests pass.
* fix tests for pre-C++17
Office is seeing build breaks due to `#include "span"` including
C++20 span instead of gsl/span. Most likely we want all headers
includes qualified with "gsl/" to avoid similar issues.
- `strict_not_null<std::unique_ptr<int>>{ std::make_unique<int>()}` failed to compile
- `strict_not_null` ctor needs to move the passed `unique_ptr`, not copy
- Copied `not_null` `TestNotNullConstructors` for `strict_not_null`
- The `noexcept` specifiers on the `strict_not_null` and `not_null` constructors were out of sync.
- Added unit test for `not_null<unique_ptr<T>>` and for `strict_not_null<unique_ptr<T>>`
- Added unit test for `gsl::swap` for two `strict_not_null`
- Added unit test for `gsl::swap` for `not_null` and `strict_not_null`
Co-authored-by: Werner Henze <w.henze@avm.de>
* this commits adds tests that should fail, but don't
* Better use of std::enable_if
Replace the occurances of `class = std::enable_if_t<Cond>` and `typename = std::enable_if_t<Cond>` that have been identified in the previous commit with `std::enable_if_t<Cond, bool> = true`.
This commit is inspired by #1174, which changed one occurance in the owner header. This commit is aimed to fix all remaining occurances.
* fix failing checks
- core.cxx_gsl aktualisiert auf [](https://gitlab.avm.de/fos/repos/core.cxx_gsl/-/commit/)
- plc.access_lib aktualisiert auf [](https://gitlab.avm.de/fos/repos/plc.access_lib/-/commit/)
- plc.common aktualisiert auf [](https://gitlab.avm.de/fos/repos/plc.common/-/commit/)
- plc.daemon aktualisiert auf [](https://gitlab.avm.de/fos/repos/plc.daemon/-/commit/)
-
Test Plan:
-
---------
Co-authored-by: Werner Henze <werner.henze+gitcommits@posteo.de>
Co-authored-by: Werner Henze <w.henze@avm.de>
When setting `GSL_USE_STD_BYTE` to zero, then the unit test does not compile because `byte` is ambiguous (could be `std::byte` or `gsl::byte`). So `gsl::` prefix is needed for `byte`.
It looks like the unit tests never ran on a platform where `gsl::byte` is not based on `std::byte`.
It does not make much sense to test `std::byte` for compliance, so make the unit tests based on the GSL implementation of `gsl::byte` (`#define GSL_USE_STD_BYTE 0`).
Co-authored-by: Werner Henze <werner.henze+gitcommits@posteo.de>
`std::enable_if_t` must not be used as a default template argument, otherwise the instantiator will be able to override it freely with something that doesn't fail substitution. Instead, `std::enable_if_t` itself must be the type of the template argument.
More information in the examples here: https://en.cppreference.com/w/cpp/types/enable_if
* fix failing pipeline tests
* upgrade to googletest v1.14.0 so it works with newer cmake versions
* fix android pipeline to permit new cmake versions (short-term fix)
* improve performance of span_iterator w/ clang
Issue: #1165
Before this PR, the range-for loop was ~3300x slower. After this PR, it
is ~1.005x slower
The clang optimizer is very good at optimizing `current != end`, so
we changed to this idiom. This moves the Expects assertion into the
constructor instead of on the hot-path which is called whenever either
operator++ or operator* is called.
Note: The codegen for the assertion is still a missed optimization,
but less worrisome as it only happens once per iterator.
Note: benchmarks on M1 Macbook Pro w/ Apple Clang 16.0.0
* Remove unused headers from gsl/pointers
forward is already declared in utility, no need to include algorithm which is relativaly heavy
hash is already declared in memory, no need to bring brand-new header system_error for hash only
* Fix: add missing header <functional> to gsl/pointers due to using less/greater
move pipeline testing from AzDO to GitHub Actions.
* update clang versions to 13-15
* update gcc versions to 10-12
* update xcode versions to 14.3.1 and 15.4
* test against C++23 (where supported)
Job has been failing for months and is preventing other PRs from getting
merged. This PR fixes the pipeline - it changed the following:
- runs on macos-latest-large (which is a non-arm image)
- starts the emulator under java8 (see
https://learn.microsoft.com/en-us/java/openjdk/transition-from-java-8-to-java-11)
- runs emulator with -no-audio
The above were requirements to get the pipeline running. Other changes
include the following:
- The job will auto-cancel when a newer commit is pushed to the
PR.
- The 'Wait for emulator ready' step now has a 2 minute timeout. This
is necessary because we get no indication on whether or not the
command that started the emulator suceeded. I believe there is room
for improvement here, but it is outside the scope of the PR.
Two warnings were being emitted in the MSVC+LLVM tests.
The warning `-Wunsafe-buffer-usage` is initially introduced in some capacity here https://reviews.llvm.org/D137346 pointing to documentation at https://discourse.llvm.org/t/rfc-c-buffer-hardening/65734. The warning is a stylistic checker whose goal is to "emit a warning every time an unsafe operation is performed on a raw pointer". This type of programming model is not useful for library implementations of types such as `span`, where direct manipulation of raw pointers is inevitable, so disable the warning altogether.
There is also a false-positive warning https://github.com/llvm/llvm-project/issues/65689 that I've disabled inline.
- Add anchor for `finally` in `headers.md` so that the link in `README.md` can work
- In `README.md` add code formatting for the character types of the `zstring` and `string_span` types
- In `README.md` change code formatting to links for GSL types
- Vertical alignment
Without this change a `gsl::not_null<class_type>` triggers these `noexcept` warnings:
```
.../gsl/include/gsl/pointers:162:50: warning: noexcept-expression evaluates to ‘false’ because of a call to ‘constexpr gsl::details::value_or_reference_return_t<T> gsl::not_null<T>::get() const [with T = class_type*; gsl::details::value_or_reference_return_t<T> = class_type* const]’ [-Wnoexcept]
162 | const not_null<U>& rhs) noexcept(noexcept(lhs.get() == rhs.get()))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../gsl/include/gsl/pointers:119:55: note: but ‘constexpr gsl::details::value_or_reference_return_t<T> gsl::not_null<T>::get() const [with T = class_type*; gsl::details::value_or_reference_return_t<T> = class_type* const]’ does not throw; perhaps it should be declared ‘noexcept’
119 | constexpr details::value_or_reference_return_t<T> get() const
| ^~~
```
Co-authored-by: Werner Henze <w.henze@avm.de>
Headers that were previously prefixed with `gsl_` were renamed to drop the `gsl_` prefix in https://github.com/microsoft/GSL/pull/946, and the original version deprecated.
The deprecation happened a long time ago, so it is now time to remove these headers entirely.
Turns out supporting GSL.natvis perfectly is quite difficult.
There is no universal way to consume .natvis files that would satisfy everyone.
I thought the solution was to use the /NATVIS linker option. But it turns out that actually embeds information into the PDB. So I'm not sure how to properly support the Ninja generator...
That's not even accounting for the fact target_link_options doesn't play nicely with /NATVIS
When you just add the file via target_sources the visual studio solution will just pick it up and recognize it without adding it to the PDB file. Which won't affect the binary and is what most devs want.
This all comes down to the fact that /NATVIS files have native integration with visual studio that makes it difficult to use with non-visual studio solutions. /NATVIS almost works but embeds itself into the PDB which not everyone wants, and not everyone generates PDBs either.
Docs for natvis files and /NATVIS
- https://learn.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2022
- https://learn.microsoft.com/en-us/cpp/build/reference/natvis-add-natvis-to-pdb?view=msvc-170
So my current solution is to just simplify the existing CMake code, and install the natvis so the user can decide.
closes#1084
Using `<`,`<=`,`>`,`>=` to compare unrelated pointers gives an unspecified result according to the standard.
This PR replaces the usage of these operators in `gsl::not_null` with the STL counterparts, which would leverage any implementation-defined strict total ordering for pointers.
Resolves#880