* Added c++17 test configurations for clang5.0 and clang6.0
* Fixed CppCoreCheck warnings in GSL and tests
- Added CMakeSettings.json for VS Open Folder configuration
- So we can easily run CppCoreCheck in VS
- Fixed CppCorecheck warnings where it made sense
- Suppressed the rest
- Some suppression does not work due to compiler/tool bugs,
so replaced by #pragma disable
- CppCoreCheck has noise, suppressed those with comments
- Catch produces many warnings, blanket-supressed them all
- Had to fix clang formatting to keep attributes in place
- clang-format does not support attributes, so I am using
- "CommentPragmas: '^ NO-FORMAT:'" to skip formatiting on them
- Removed GSL_NOEXCEPT macro, removed incorred noexcepts
* Ignore unknown attributes
* ignore unknown attributes in noexception mode tests
* fixed C26472 in at()
* created GSL_SUPPRESS macro to allow all compilers to parse suppression attributes
* try to fix gcc compilation problems with attributes
* ignore gsl::suppress for gcc
* move suppression to function level on return statements
clang5.0 and up does not allow attributes on return statemets in constexpr functions
* move suppression to function level on return statements
* use GSL_SUPPRESS in algorithm_tests
* Addressed PR comments
* Added c++17 test configurations for clang5.0 and clang6.0
* removed GSL_NOEXCEPT
- Removed GSL_NOEXCEPT macro
- Replaced by noexcept keyword when needed
- removed noexcept where a function could throw
* remove unneded undef
* fixed replace errors
* removed noexcept where function can throw
* Explicitly check for availbility of std::byte
GCC > 7.3 defines __cpp_lib_byte >= 201603 when std::byte is available.
On libc++ std::byte is available since version 5.0. This can be checked
with _LIBCPP_VERSION >= 5000.
This fixes 713.
* Add missing \ in preprocessor check
- gsl::narrow, gsl::narrow_cast and gsl::at are the safe variants suggested by CppCoreGuideline. It does not make sense to let VS warn inside the implementation of these functions that unsafe static_cast is used and that the safe variants shall be used.
- Suppress warning that throw_exception can be declared noexcept (for the GSL_TERMINATE_ON_CONTRACT_VIOLATION case)
* Added template argument deduction for not_null
This allows compilers with c++17 support to infer template
instantiation types when calling not_null constructor:
int foo(not_null<const int*> x);
int main()
{
int t = 0;
not_null x{ &t };
return foo(not_null{ &t });
}
* replaced deduction guides by a simple constructor
* Updated tests
* fixed check for availability of std::byte
* testing c++1z on clang
* fixed cmakelists extra endif
* include cstddef header for clang and gcc in pointers
* fixed a typo
* fix missing nullptr_t type
* fixed typo in CMakeLists.tst
* change approach to c++17 testing, step one: revert cmake testing, update clang5.0 package
removed using latest c++ due to clang5.0 failing,
update clang5.0 travis config to use llvm-toolchain-trusty-5.0
* addressed comments
* Add usage for check-and-unwrap of MS STL iterators
This is Billy ONeal's PR #682 with a typo fixed.
See corresponding change here:
ca77129308
That change officially exposes the STL's range checking machinery,
available in MSVC++ "15.8"+
This change augments GSL span::iterator to call into that newly exposed
machinery.
_Verify_range(cit, cit)
Requests that the iterator type check that the parameters form a valid
[First, Last) range iterator pair. This replaces _DEBUG_RANGE and
supporting machinery. The standard library provides a version for
pointers under _IDL != 0; otherwise they are normally provided via
hidden friend functions. Note that declaring some of these hidden
friends for "wrapper" iterators like move_iterator and reverse_iterator
triggers VSO#610735.
cit._Verify_offset(difference_type _Off)
For random-access iterators, performs any asserts that would be
performed by i += _Off; except with possibly a better error message and
without moving the iterator.
cit._Unwrapped()
Returns an "unchecked" or "unwrapped" iterator which has previously been
validated. The iterator may have been validated by a call to
_Verify_range or _Verify_offset (above), or by seeking a checked
iterator to a "high water mark" point.
it._Seek_to(cit) / it._Seek_to(return value from _Unwrapped())
Moves the position of the checked iterator it to the position of the
unchecked iterator supplied. Generally not intended to perform range
checks.
* Fixed build break in VS2015
* fixed constexpr build break when using VS2015
* [span] implement non-member + as a hidden friend
Drive-by: remove garbage `operator-(difference_type, span_iterator)`.
* [span] Use pointers for range-based-for on MSVC
C++17 defines `std::byte*` to have the same aliasing properties as
`char*`. Hence, we mark it with the `__may_alias__` attribute under gcc
and clang.
Based on the fix by Martin Moene in byte-lite.
Fixes#663
This fixes the build with clang 7 which introduces a new warning
`-Wreturn-std-move` which warns about needless copies when a move
operation is available (see https://reviews.llvm.org/rL329914).
We take the exception object by uref so we should throw the forwarded
version.
* Enable usage of gsl::narrow with exceptions disabled
This solution uses the approach of boost::asio to enabling usage of the
library in environments where exception usage is either prohibited
or not feasible (due to code size constraints). A function template
gsl::throw_exception has been added, which in a normal environment just
throws the exception. However, when GSL_TERMINATE_ON_CONTRACT_VIOLATION
is defined the function is only declared by gsl and the definition of
this function template must be supplied by the library's user.
Closes: #468
Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
Addition:
- understand STL no exception macro
- use function static variable to set termination handler in kernel mode
- add compile-only tests for no-exception mode
* added termination tests and fixed bugs
* disabled warning C4577 for msvc 2015
* Added support for returning fixed-spize spans from subspan().
* Addressed issues from code review.
* Took simpler approach to static data member.
* Subtle fix to support MSVC 15.
* Helps to not introduce extraneous >
* fixed noexept warnings
- Removed conditional compilation for throwing version of GSL
vs fail_fast because we don't want users of the code to see
differences in the span interface dependent on error mechanism
chosen
- Removed noexcept from functions that may fail at runtime
- Fixed CppCoreCheck warnings related to missing and incorrect
noexcept
- do not warn on unnown attributes for GCC and Clang
* remove suppress that does not compiler for clang and gcc
Resolves compiler code analysis warning ...\gsl\include\gsl\string_span(101): warning C26496: The variable 'str_span' is assigned only once, mark it as const (con.4: https://go.microsoft.com/fwlink/p/?LinkID=784969).
* rewrite span subspan checks to help optimizations
* Removed checking pointer for null for subspans. We would never
check pointer for null in between ptr and ptr+size in the
original span, so there seems to be no reason to do so for
subspans, provided that the subspan's boundaries are ensured
to be within the range of the original span's boundaries.
This change allows to simplify generated code, for example, to
remove 5 out of 9 branches in code generated from the following
by MSVC, and 4 out 8 branches in clang and gcc-generated code:
span<int> mysubspan(int* p, std::ptrdiff_t size, std::ptrdiff_t i)
{
if (p != nullptr)
{
span<int> s = { p, size };
return s.subspan(i);
}
return { nullptr };
}
Similar effects are achieved for dynamic subspans of static spans,
where in the following code we remove 2 out of 4 branchs in MSVC
and GCC-generated code:
int test_dynamic_subspan_of_static_span(std::ptrdiff_t i)
{
int x[] = { 0,1,2,3,4,5 };
span<int, 6> s = { x };
auto subspan = s.subspan(i);
return subspan.size();
}
* Made string_span details::string_length() generic
removed overloads & specialized classes
Creating string_spans using `char16_t` and `char32_t` was not possible
without creating new specializations and function overloads.
This patch makes details::string_length() generic removing the need to
extend the overloads and specializations.
* added type aliases for string_span types char16_t and char32_t
* Added char16_t & char32_t overloads for ensure_z
* added string_span tests for char16_T & char32_t
* added zstring type aliases for char16_t & char32_t
* Added tests for char16_t & char31_t zstring and string_span types
* applies clang format to <gsl/string_span>
* Clang format tests/string_span_tests.cpp
* Removed ensure_z() overloads as they don't add functionality.
using the GSL with MSVC 2017 causes the following warning"
`'std::copy_n::_Unchecked_iterators::_Deprecate': Call to 'std::copy_n'`
This patch removes this since the point of this code is to deal with this issue.
not called even by the unit test (it was calling the "container" ctor
instead). I mimicked the constructor taking a non-const std::array to fix
the issue.
* Fixes issue with dereferencing operator issue #491 introduced in PR #513
dereferencing operator added in PR#513 returned a copy of the object
instead of reference to it.
Adding decltype(auto) as return type of operator* fixes this issue.
* added more tests for not_null::operator*
* Restricting usage of owner<T> to pointer types
* Removing an additional type that was created for testing
* Added comment about the new constraint on owner
* Adding dereference operator to not_null
* Removing dereference operator changes for not-null
* Removing dereference operator changes for not-null
* Review comments
Fixes#510.
* Constrain the converting constructor to not participate in overload resolution when IsConst is true, so that it is never a copy constructor.
* Use Default Member Initializers for span_iterator's data members so that the default constructor can be explicitly defaulted.
* Declare all members of span_iterator GSL_NOEXCEPT: they only throw when contract violations throw.
* Don't use & in operator-> since evil types may overload it.
Project files were not following the clang-format style. For people
using IDEs were clang-format is always run after a save this would
cause unwanted changes.
This commit only applies "clang-format -i" to files.
* Add value_type to span
Currently I'm working on project which involves a lot of `span`s and mocking via Google Mock. Unfortunately a lot of standard matchers requires `value_type` type definition inside container which `gsl::span` lacks.
This pull request add `value_type` type definition inside `gsl::span`
* Strip cv from value_type of span and span_iterator
* Added support of not_null<smart_ptr> comparison
* The return type of not_null comparison operators is determined using SFINAE
#474
* tests for gsl::not_null comparison were added
* not_null comparison tests were rewritten to compare pointers to objects located in the same array
* not_null<shared_ptr> comparison was simplified
* initializer_list overload returns by value to avoid lifetime issues
* generic overload uses expression SFINAE to work with any type that has member size() and operator[], which notably includes const/non-const vector and array.
* Add test coverage for const objects, rvalue initializer_lists, and constexpr usage.
Fixes#357.
* Improve const correctness in string_span
* Improve const correctness in bounds_tests.cpp and byte_tests.cpp
* Improve const correctness in span_tests.cpp
* Improve const correctness in utils_tests.cpp
* Use gsl::owner for dynamically allocated memory in string_span_tests.cpp
* Improve const correctness in string_span_tests.cpp
* Improve const correctness for strided_span_tests.cpp
* GSL_LIKELY/_UNLIKELY always contextually convert their argument to bool.
* Add macro GSL_ASSUME(cond) to inform the optimizer that the predicate cond must hold.
* Reimplement Expects & Ensures as expressions for flexibility and correctness. (Think about "if (cond1) Expects(cond2); else goto fail;")
* Expects and Ensures GSL_ASSUME their predicate when GSL_UNENFORCED_ON_CONTRACT_VIOLATION is defined.
* add gsl::not_null operator<<
Hippomocks, which is a popular mocking engine for C++ uses operator<< on pointers and gets confused about gsl::not_null not having this operator.
* Update gsl
* constexpr all the things.
* remove operator=(const T&)
* it leaves *this in an invalid state if ensure_invariant fails
* implicitly converting the T to not_null and then assigning is in every way superior.
* simplify conversion from not_null<U> with constructor delegation.
* remove the converting assignment operator; again let the conversion constructor and self-assignment operator do the work.
* Cover the remaining pointer arithmetic operations as Wakely suggests in issue #447.
* Cleanup not_null conversions from null pointer constants:
* replace constructor that accepts T with constructor template that accepts U convertible to T
* remove deleted constructor that accepts int
* Attempts to initialize with nullptr, 0, 0L, 0LL, etc. all unambiguously select the deleted nullptr_t constructor.
* Nest "gsl" directory inside a new "include" directory.
* Cleanup the _MSC_VER conditionals a bit; use constexpr on VS2017+.
* Don't #define noexcept on non-Microsoft implementations.
* Workaround VS2017 bug in multi_span. (Also implement == and != for static_bounds_dynamic_range_t because I'm an EoP semantic soundness snob.)
Fixes#441.
whether using it from the development folder, from the installation
folder or from being copied into a project.
#include <gsl/gsl.h>
Updated headers/tests/instructions/cmake build accordingly
This PR should address https://github.com/Microsoft/GSL/issues/277 (less
the renaming of gsl itself)
initializer_list do not have subscript operator, so the generic container overload of gsl::at fails to compile.
This commits adds an overload of gsl::at for initializer_lists, using *(initializer_list::begin()+index) instead of subscript operator