Commit Graph

34 Commits

Author SHA1 Message Date
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
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
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
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
beinhaerter
ef0ffefe52
is_comparable_to_nullptr for better static_assert (#975)
* is_comparable_to_nullptr for better static_assert

Trying `gsl::not_null<char> p2{ 0 };` on VS2019 the current implementation would trigger

>error C2446 : '!=' : no conversion from 'nullptr' to 'int'
>message: A native nullptr can only be converted to bool or , using reinterpret_cast, to an integral type
>message: see reference to class template instantiation 'gsl::not_null<char>' being compiled
>error C2955 : 'std::is_convertible' : use of class template requires template argument list
>message: see declaration of 'std::is_convertible'
>error C2039 : 'value' : is not a member of 'std::is_convertible<_From,_To>'
>error C2065 : 'value' : undeclared identifier


The new implementation gives much shorter and clearer message and does exactly as the `static_assert` intends to do:

> error C2338: T cannot be compared to nullptr.
> message : see reference to class template instantiation 'gsl::not_null<char *>' being compiled

* Update include/gsl/pointers

Co-authored-by: Casey Carter <cartec69@gmail.com>

Co-authored-by: Werner Henze <w.henze@avm.de>
Co-authored-by: Casey Carter <cartec69@gmail.com>
2021-02-24 14:39:13 -08:00
Jordan Maples [MSFT]
a150aaa4ed
renaming main logic files. Added warning message of the removal and include passthrough. Renamed includes in the source files. Ran Clang-Format (#946)
Header rename
2020-10-29 17:38:48 -07:00
mtnpke
736b62a838
Allow usage on platforms not providing iostreams (#935)
Closes #933.
2020-10-28 15:37:02 -07:00
Jordan Maples
4a4bb3c13a adding changes suggested by Jonathan Wakely 2020-08-26 16:51:58 -07:00
Jonathan Wakely
e09326eefd Pass correct value to std::hash 2020-08-13 12:59:01 +01:00
Jordan Maples [MSFT]
ef714fa49e
Merge pull request #676 from ericLemanissier/patch-3
fix requirement on not_null template
2020-08-12 15:28:25 -07:00
Jordan Maples [MSFT]
f79ed1bb5c
Merge pull request #876 from beinhaerter/make_notnull_noexcept
noexcept for make_(strict_)not_null and not_null comparisons
2020-07-15 14:36:17 -07:00
Jordan Maples
478d876951 remove pragma pop for constexpr macro 2020-07-15 11:43:29 -07:00
Jordan Maples
853b061141 remove msvc < 1910 checks as those versions are no longer supported. 2020-07-15 11:38:41 -07:00
Werner Henze
29297e7dac noexcept for make_(strict_)not_null and not_null comparisons 2020-04-27 14:42:56 +02:00
Jordan Maples [MSFT]
6b23937baf remove move constructor for not_null. 2020-01-30 17:00:13 -08:00
Jordan Maples [MSFT]
263440f2a1 changing white-space in comment to get tests to rerun 2019-11-18 11:39:36 -08:00
Jordan Maples [MSFT]
a7759e6d3f lower __cpp_deduction_guide version number from 201907 to 201611 2019-11-18 10:14:05 -08:00
Jordan Maples [MSFT]
128b4356ac changing check from __cplusplus 201703L to __cpp_deduction_guides 201907L 2019-11-15 16:29:41 -08:00
Jordan Maples [MSFT]
8e481ebe19 adding deduction guide for strict_not_null 2019-11-15 14:41:38 -08:00
Jordan Maples [MSFT]
4610f26b33 forgot comment 2019-11-15 12:43:33 -08:00
Jordan Maples [MSFT]
d0e5daf441 fix ctad warning in llvm 2019-11-15 12:11:44 -08:00
Sergei Izmailov
275e0176c0 Fix typos in gsl/pointers 2019-10-06 19:20:15 +03:00
Anna Gringauze
6418b5f4de
Clang cl (#762)
* Added c++17 test configurations for clang5.0 and clang6.0

* Fix #739 correct cppcorecheck warnings for clang-cl

* Add clang-cl  configurations

* Corrections Appveyor;
Temporarily disable msvc compilation for faster testing (#741)

* Add path to clang-cl.exe (#741)

* Escape backslash in path (#741)

* Update vcpkg (#741)

* Check vcpkg version; try without building vcpkg; use latest clang-cl from path (#741)

* Fix blocks in ps script (#741)

* Try accessing APPVEYOR_BUILD_FOLDER variable (#471)

* Update span size() bug confirmation test for GCC 6.5 (#741)

* MSVC flags to Clang-cl; disable c++98-compat and undefined macro warnings (#741)

* Suppress clang warning on tests (missing-prototypes) (#741)

* Fix clang warning -Wnewline-eof (#741)

* Fix clang warning -Wdouble-promotion (#741)

* Set linker explicitly

* Clean condition statement

* For Clang, fallback to the AppVeyor installed version of CMake

* Fix clang warning -Wmissing-variable-declarations

* Fallback to the MSVC linker until vcpkg has been updated

* Revert "Fallback to the MSVC linker until vcpkg has been updated"

This reverts commit 7263f3289e.

* Fix clang warning -Wunused-member-function

* Fix clang warning -Wmissing-noreturn

* Fix clang warning -Winvalid-noreturn on Windows

* Add macro block end comment on large #if blocks

* Workaround: fallback to mscv link.exe

* Workaround: get msvc paths into PowerShell through intermediate file

* Workaround: fix, remove "PATH=" from text

* Workaround: try with full-path; and return user PATH

* Workaround: fix, escape backslashes

* Revert all since "Workaround: fallback to mscv link.exe" did not work on AppVeyor

This reverts the commits:
bda3d6a428
97062933ac
0f4fb04bac
1b0c19afd1
a5739ea5f0

* Suppress output of git pull; remove vcpkg from cache

* Re-enable AppVeyor builds for all platforms

* Correct typo

Co-Authored-By: Farwaykorse <Farwaykorse@users.noreply.github.com>

* Add Clang-cl 7.0.0 to the supported platforms

* Revert "Fix clang warning -Wunused-member-function"

This reverts commit 6fe1a42035.

* Fix or locally suppress clang warning -Wunused-member-function

* format touched code and correct comment

* git pull --quiet

* fix logic error in workaround

* fix missing bracket

* Suppress output of mkdir

* Replace MSBuild with Ninja

* Suppress output of 7z

* Add architecture flags for Clang

* Drop workaround for lld-link

* 7-zip Overwrite and Alternative output suppression without suppressing errors

Replaces 3c1c0794dd

* AppVeyor setup and CMake before build

* reorder compiler configuration

* remove unnecessary

* remove -fno-strict-aliasing

* remove -Wsign-conversion, since before v4.0 part of -Wconversion

* -Wctor-dtor-privacy is GCC only

* remove -Woverloaded-virtual part of -Wmost, part of -Wall

* add -Wmissing-noreturn

* remove the pragmas for -Wunused-member-function

* Re-add MSBuild generator on AppVeyor

* Print CMake commands

* Add MSBuild toolset selection

* Separate Architecture setting

* clang-cl: add -Weverything

* clang-cl -Wno-c++98-compat

* clang-cl -Wno-c++98-compat-pedantic

* clang-cl -Wno-missing-prototypes

* clang-cl C++14 -Wno-unused-member-function

* clang-cl -Wundef __GNUC__

* clang++: add -Weverything

* clang++ -Wno-c++98-compat

* clang++ -Wno-c++98-compat-pedantic

* clang++ -Wno-missing-prototypes

* clang++ -Wno-weak-vtables

* clang++ C++14 -Wno-unused-member-function

* clang++ fix -Wundef _MSC_VER

* clang++ -Wno-padded

* clang++ solve -Wdeprecated

* Add AppleClang compiler target
Since CMake v3.0 use of Clang for both is deprecated

* clang++ v5.0 C++17 -Wno-undefined-func-template

* Add VS2015 + LLVM/clang-cl to AppVeyor

* Do not disable constexpr when compiling with clang-cl on Windows

* Clean-up clang-only warnings (now under -Weverything)

* Revert "Fix clang warning -Winvalid-noreturn on Windows"

This reverts commit 2238c4760e.

* Suppress -Winvalid-noreturn for the MS STL noexception workaround

* CMake: put preprocessor definition in target_compile_definitions

* Solve compiler warning C4668: __GNUC__ not defined
2019-01-15 10:27:34 -08:00
Anna Gringauze
9ff6e19ea9
Dev/annagrin/remove explicit not null constructor (#743)
* Added c++17 test configurations for clang5.0 and clang6.0

* Removed explicit not_null constructor, sloppy_not_null, added strict_not_null

We added explicit not_null constructor in version 2.0.0.
It proved very difficult to switch to the new version for
large code bases that adopted previous versions of gsl,
due to not_null used extensively in the code. Still, using
explicit constructor is very benefitial for new code, since
it encorages better API design and make null checks intentional.

To resolve the issue, this change:
- removes explicit keyword from not_null constructor
- removes unneded sloppy_not_null type
- adds strict_not_null type to behave the same way as v2 not_null
- updates tests

* Removed explicit not_null constructor, sloppy_not_null, added strict_not_null

We added explicit not_null constructor in version 2.0.0.
It proved very difficult to switch to the new version for
large code bases that adopted previous versions of gsl,
due to not_null used extensively in the code. Still, using
explicit constructor is very benefitial for new code, since
it encorages better API design and make null checks intentional.

To resolve the issue, this change:
- removes explicit keyword from not_null constructor
- removes unneded sloppy_not_null type
- adds strict_not_null type to behave the same way as v2 not_null
- updates tests

* fixed build break for gcc7

* added more tests

* added more non-compiling tests

* Addressed PR comments and suppressed a code analysis warning

* Fixed test failure in not_null tests
2019-01-14 16:45:47 -08:00
Anna Gringauze
831584d947
Dev/annagrin/make not null (#711)
* Added c++17 test configurations for clang5.0 and clang6.0

* Added make_not_null helper to create a not_null

Introduction of explicit not_null constructor made it cumbersome to create not_nulls
in c++14. Adding make_not_null helper. Usage (see tests):

int i = 42;

auto x = make_not_null(&i);
helper(make_not_null(&i));
helper_const(make_not_null(&i));

* Added std::forward to make_not_null, fixed some code analysis warnings

* Fix build break in VS2015 Release configuration

* Fix build break in VS2015 Release configuration
2018-08-13 02:22:02 -07:00
Anna Gringauze
cb2d1af89a
Added template argument deduction for not_null (#689)
* 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
2018-06-07 13:36:56 -07:00
ericLemanissier
423841e965
fix requirement on not_null template
it should be comparable to nullptr, it does not have to be assignable
2018-05-03 08:08:41 +02:00
ericLemanissier
2fc94db3eb not_null constructor is now explicit (#659)
solves #395
2018-04-24 19:11:43 -07:00
Zac Hansen
ed3693fd2e make explicit not_null move constructor so it is noexcept (#630)
* make explicit not_null move constructor so it is noexcept

* added test for not_null being noexcet move constructible
2018-03-03 15:53:23 -08:00
Tiago
0d33bf6794 Applied iwyu --comment to the code base (#588) 2017-11-28 07:13:49 -08:00
bjude
7e529a47c2 Remove #pragma once (#545) (#570)
Core Guidelines SF.8 recommends using portable include guards instead.
2017-11-14 08:38:16 -08:00
menete
2ad93a38dd Iosfwd (#586)
* Solves #567 with <iosfwd> approach

* adds a little testing to not_null ostream
2017-11-14 08:14:20 -08:00
Tiago
d10ebc6555 Drop "Dummy" from enable_if in templates (#572)
Looks like this was here because of MSVC 2013 compat which is not
supported anymore
2017-11-03 16:18:59 -07:00
Tiago
4862a270b9 Move GSL pointers to a separate header (#566) 2017-10-31 10:19:12 -07:00