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 19:45:47 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// This code is licensed under the MIT License (MIT).
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-05-20 21:18:08 -04:00
|
|
|
#include <gsl/pointers> // for not_null, operator<, operator<=, operator>
|
2019-12-03 17:32:25 -05:00
|
|
|
#include <gtest/gtest.h>
|
2021-05-20 21:18:08 -04:00
|
|
|
|
2025-01-04 12:50:31 -05:00
|
|
|
#include <type_traits> // for declval
|
|
|
|
|
2021-05-20 21:18:08 -04:00
|
|
|
#include "deathTestCommon.h"
|
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 19:45:47 -05:00
|
|
|
|
|
|
|
using namespace gsl;
|
|
|
|
|
2025-01-04 12:50:31 -05:00
|
|
|
#if __cplusplus >= 201703l
|
|
|
|
using std::void_t;
|
|
|
|
#else // __cplusplus >= 201703l
|
|
|
|
template <class...>
|
|
|
|
using void_t = void;
|
|
|
|
#endif // __cplusplus < 201703l
|
|
|
|
|
2024-12-26 12:00:36 -05:00
|
|
|
// stand-in for a user-defined ref-counted class
|
|
|
|
template <typename T>
|
|
|
|
struct RefCounted
|
|
|
|
{
|
|
|
|
RefCounted(T* p) : p_(p) {}
|
|
|
|
operator T*() { return p_; }
|
|
|
|
T* p_;
|
|
|
|
};
|
|
|
|
|
2021-05-13 13:52:09 -04:00
|
|
|
namespace
|
|
|
|
{
|
2021-05-20 21:18:08 -04:00
|
|
|
// clang-format off
|
|
|
|
GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
|
|
|
|
// clang-format on
|
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 19:45:47 -05:00
|
|
|
bool helper(not_null<int*> p) { return *p == 12; }
|
2019-12-03 17:32:25 -05:00
|
|
|
|
2021-05-20 21:18:08 -04:00
|
|
|
// clang-format off
|
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 19:45:47 -05:00
|
|
|
GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
|
2021-05-20 21:18:08 -04:00
|
|
|
// clang-format on
|
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 19:45:47 -05:00
|
|
|
bool helper_const(not_null<const int*> p) { return *p == 12; }
|
|
|
|
|
2021-05-20 21:18:08 -04:00
|
|
|
// clang-format off
|
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 19:45:47 -05:00
|
|
|
GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
|
2021-05-20 21:18:08 -04:00
|
|
|
// clang-format on
|
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 19:45:47 -05:00
|
|
|
bool strict_helper(strict_not_null<int*> p) { return *p == 12; }
|
2019-12-03 17:32:25 -05:00
|
|
|
|
2021-05-20 21:18:08 -04:00
|
|
|
// clang-format off
|
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 19:45:47 -05:00
|
|
|
GSL_SUPPRESS(f.4) // NO-FORMAT: attribute
|
2021-05-20 21:18:08 -04:00
|
|
|
// clang-format on
|
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 19:45:47 -05:00
|
|
|
bool strict_helper_const(strict_not_null<const int*> p) { return *p == 12; }
|
|
|
|
|
|
|
|
int* return_pointer() { return nullptr; }
|
2021-05-13 13:52:09 -04:00
|
|
|
} // namespace
|
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 19:45:47 -05:00
|
|
|
|
2025-01-04 12:50:31 -05:00
|
|
|
template <typename U, typename = void>
|
|
|
|
static constexpr bool CtorCompilesFor_A = false;
|
|
|
|
template <typename U>
|
|
|
|
static constexpr bool
|
|
|
|
CtorCompilesFor_A<U, void_t<decltype(gsl::strict_not_null<void*>{std::declval<U>()})>> = true;
|
|
|
|
|
|
|
|
template <typename U, int N, typename = void>
|
|
|
|
static constexpr bool CtorCompilesFor_B = false;
|
|
|
|
template <typename U, int N>
|
|
|
|
static constexpr bool CtorCompilesFor_B<U, N, void_t<decltype(gsl::strict_not_null<U>{N})>> = true;
|
|
|
|
|
|
|
|
template <typename U, typename = void>
|
|
|
|
static constexpr bool DefaultCtorCompilesFor = false;
|
|
|
|
template <typename U>
|
|
|
|
static constexpr bool DefaultCtorCompilesFor<U, void_t<decltype(gsl::strict_not_null<U>{})>> = true;
|
|
|
|
|
|
|
|
template <typename U, typename = void>
|
|
|
|
static constexpr bool CtorCompilesFor_C = false;
|
|
|
|
template <typename U>
|
|
|
|
static constexpr bool CtorCompilesFor_C<
|
|
|
|
U, void_t<decltype(gsl::strict_not_null<U*>{std::declval<std::unique_ptr<U>>()})>> = true;
|
|
|
|
|
2024-12-26 12:00:36 -05:00
|
|
|
TEST(strict_notnull_tests, TestStrictNotNullConstructors)
|
|
|
|
{
|
|
|
|
{
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(CtorCompilesFor_A<void*>, "CtorCompilesFor_A<void*>");
|
|
|
|
static_assert(!CtorCompilesFor_A<std::nullptr_t>, "!CtorCompilesFor_A<std::nullptr_t>");
|
|
|
|
static_assert(!CtorCompilesFor_B<void*, 0>, "!CtorCompilesFor_B<void*, 0>");
|
|
|
|
static_assert(!DefaultCtorCompilesFor<void*>, "!DefaultCtorCompilesFor<void*>");
|
|
|
|
static_assert(!CtorCompilesFor_C<int>, "CtorCompilesFor_C<int>");
|
2024-12-26 12:00:36 -05:00
|
|
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
|
|
|
// Forbid non-nullptr assignable types
|
|
|
|
strict_not_null<std::vector<int>> f(std::vector<int>{1});
|
|
|
|
strict_not_null<int> z(10);
|
|
|
|
strict_not_null<std::vector<int>> y({1, 2});
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto terminateHandler = std::set_terminate([] {
|
|
|
|
std::cerr << "Expected Death. TestNotNullConstructors";
|
|
|
|
std::abort();
|
|
|
|
});
|
|
|
|
const auto expected = GetExpectedDeathString(terminateHandler);
|
|
|
|
|
|
|
|
{
|
|
|
|
// from shared pointer
|
|
|
|
int i = 12;
|
|
|
|
auto rp = RefCounted<int>(&i);
|
|
|
|
strict_not_null<int*> p(rp);
|
|
|
|
EXPECT_TRUE(p.get() == &i);
|
|
|
|
|
|
|
|
strict_not_null<std::shared_ptr<int>> x(
|
|
|
|
std::make_shared<int>(10)); // shared_ptr<int> is nullptr assignable
|
|
|
|
|
|
|
|
int* pi = nullptr;
|
|
|
|
EXPECT_DEATH((strict_not_null<decltype(pi)>(pi)), expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// from unique pointer
|
|
|
|
strict_not_null<std::unique_ptr<int>> x(
|
|
|
|
std::make_unique<int>(10)); // unique_ptr<int> is nullptr assignable
|
|
|
|
|
|
|
|
EXPECT_DEATH((strict_not_null<std::unique_ptr<int>>(std::unique_ptr<int>{})), expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// from pointer to local
|
|
|
|
int t = 42;
|
|
|
|
|
|
|
|
strict_not_null<int*> x{&t};
|
|
|
|
helper(&t);
|
|
|
|
helper_const(&t);
|
|
|
|
|
|
|
|
EXPECT_TRUE(*x == 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// from raw pointer
|
|
|
|
// from strict_not_null pointer
|
|
|
|
|
|
|
|
int t = 42;
|
|
|
|
int* p = &t;
|
|
|
|
|
|
|
|
strict_not_null<int*> x{p};
|
|
|
|
helper(p);
|
|
|
|
helper_const(p);
|
|
|
|
helper(x);
|
|
|
|
helper_const(x);
|
|
|
|
|
|
|
|
EXPECT_TRUE(*x == 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// from raw const pointer
|
|
|
|
// from strict_not_null const pointer
|
|
|
|
|
|
|
|
int t = 42;
|
|
|
|
const int* cp = &t;
|
|
|
|
|
|
|
|
strict_not_null<const int*> x{cp};
|
|
|
|
helper_const(cp);
|
|
|
|
helper_const(x);
|
|
|
|
|
|
|
|
EXPECT_TRUE(*x == 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// from strict_not_null const pointer, using auto
|
|
|
|
int t = 42;
|
|
|
|
const int* cp = &t;
|
|
|
|
|
|
|
|
auto x = strict_not_null<const int*>{cp};
|
|
|
|
|
|
|
|
EXPECT_TRUE(*x == 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// from returned pointer
|
|
|
|
|
|
|
|
EXPECT_DEATH(helper(return_pointer()), expected);
|
|
|
|
EXPECT_DEATH(helper_const(return_pointer()), expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-04 12:50:31 -05:00
|
|
|
template <typename U, typename = void>
|
|
|
|
static constexpr bool StrictHelperCompilesFor = false;
|
|
|
|
template <typename U>
|
|
|
|
static constexpr bool
|
|
|
|
StrictHelperCompilesFor<U, void_t<decltype(strict_helper(std::declval<U>()))>> = true;
|
|
|
|
|
|
|
|
|
|
|
|
template <typename U, typename = void>
|
|
|
|
static constexpr bool StrictHelperConstCompilesFor = false;
|
|
|
|
template <typename U>
|
|
|
|
static constexpr bool
|
|
|
|
StrictHelperConstCompilesFor<U, void_t<decltype(strict_helper_const(std::declval<U>()))>> =
|
|
|
|
true;
|
|
|
|
|
|
|
|
|
|
|
|
template <typename U, typename = void>
|
|
|
|
static constexpr bool HelperCompilesFor = false;
|
|
|
|
template <typename U>
|
|
|
|
static constexpr bool HelperCompilesFor<U, void_t<decltype(helper(std::declval<U>()))>> = true;
|
|
|
|
|
2019-12-03 17:32:25 -05:00
|
|
|
TEST(strict_notnull_tests, TestStrictNotNull)
|
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 19:45:47 -05:00
|
|
|
{
|
|
|
|
{
|
|
|
|
// raw ptr <-> strict_not_null
|
|
|
|
int x = 42;
|
|
|
|
|
|
|
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
|
|
|
strict_not_null<int*> snn = &x;
|
|
|
|
#endif
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(!StrictHelperCompilesFor<int*>, "!StrictHelperCompilesFor<int*>");
|
|
|
|
static_assert(!StrictHelperConstCompilesFor<int*>,
|
|
|
|
"!StrictHelperCompilesFor<int*>");
|
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 19:45:47 -05:00
|
|
|
|
|
|
|
const strict_not_null<int*> snn1{&x};
|
|
|
|
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(StrictHelperCompilesFor<const strict_not_null<int*>>,
|
|
|
|
"StrictHelperCompilesFor<const strict_not_null<int*>>");
|
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 19:45:47 -05:00
|
|
|
helper(snn1);
|
|
|
|
helper_const(snn1);
|
|
|
|
|
2019-12-04 16:46:50 -05:00
|
|
|
EXPECT_TRUE(*snn1 == 42);
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
2023-02-06 16:16:06 -05:00
|
|
|
{
|
|
|
|
// raw ptr <-> strict_not_null
|
|
|
|
const int x = 42;
|
|
|
|
|
|
|
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
|
|
|
strict_not_null<int*> snn = &x;
|
|
|
|
#endif
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(!StrictHelperCompilesFor<const int*>, "!StrictHelperFor<const int*>");
|
|
|
|
static_assert(!StrictHelperConstCompilesFor<const int*>,
|
|
|
|
"!StrictHelperCompilesFor<const int*>");
|
2023-02-06 16:16:06 -05:00
|
|
|
|
|
|
|
const strict_not_null<const int*> snn1{&x};
|
|
|
|
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(!HelperCompilesFor<const strict_not_null<const int*>>,
|
|
|
|
"!HelperCompilesFor<const strict_not_null<const int*>>");
|
|
|
|
static_assert(StrictHelperConstCompilesFor<const strict_not_null<const int*>>,
|
|
|
|
"StrictHelperCompilesFor<const strict_not_null<const int*>>");
|
2023-02-06 16:16:06 -05:00
|
|
|
helper_const(snn1);
|
|
|
|
|
|
|
|
EXPECT_TRUE(*snn1 == 42);
|
|
|
|
}
|
|
|
|
|
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 19:45:47 -05:00
|
|
|
{
|
|
|
|
// strict_not_null -> strict_not_null
|
|
|
|
int x = 42;
|
|
|
|
|
|
|
|
strict_not_null<int*> snn1{&x};
|
|
|
|
const strict_not_null<int*> snn2{&x};
|
|
|
|
|
|
|
|
strict_helper(snn1);
|
|
|
|
strict_helper_const(snn1);
|
|
|
|
strict_helper_const(snn2);
|
|
|
|
|
2019-12-04 16:46:50 -05:00
|
|
|
EXPECT_TRUE(snn1 == snn2);
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
2023-02-06 16:16:06 -05:00
|
|
|
{
|
|
|
|
// strict_not_null -> strict_not_null
|
|
|
|
const int x = 42;
|
|
|
|
|
|
|
|
strict_not_null<const int*> snn1{&x};
|
|
|
|
const strict_not_null<const int*> snn2{&x};
|
|
|
|
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(!StrictHelperCompilesFor<strict_not_null<const int*>>,
|
|
|
|
"!StrictHelperCompilesFor<strict_not_null<const int*>>");
|
2023-02-06 16:16:06 -05:00
|
|
|
strict_helper_const(snn1);
|
|
|
|
strict_helper_const(snn2);
|
|
|
|
|
|
|
|
EXPECT_TRUE(snn1 == snn2);
|
|
|
|
}
|
|
|
|
|
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 19:45:47 -05:00
|
|
|
{
|
|
|
|
// strict_not_null -> not_null
|
|
|
|
int x = 42;
|
|
|
|
|
|
|
|
strict_not_null<int*> snn{&x};
|
|
|
|
|
|
|
|
const not_null<int*> nn1 = snn;
|
|
|
|
const not_null<int*> nn2{snn};
|
|
|
|
|
|
|
|
helper(snn);
|
|
|
|
helper_const(snn);
|
|
|
|
|
2019-12-04 16:46:50 -05:00
|
|
|
EXPECT_TRUE(snn == nn1);
|
|
|
|
EXPECT_TRUE(snn == nn2);
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
2023-02-06 16:16:06 -05:00
|
|
|
{
|
|
|
|
// strict_not_null -> not_null
|
|
|
|
const int x = 42;
|
|
|
|
|
|
|
|
strict_not_null<const int*> snn{&x};
|
|
|
|
|
|
|
|
const not_null<const int*> nn1 = snn;
|
|
|
|
const not_null<const int*> nn2{snn};
|
|
|
|
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(!HelperCompilesFor<strict_not_null<const int*>>,
|
|
|
|
"!HelperCompilesFor<strict_not_null<const int*>>");
|
2023-02-06 16:16:06 -05:00
|
|
|
helper_const(snn);
|
|
|
|
|
|
|
|
EXPECT_TRUE(snn == nn1);
|
|
|
|
EXPECT_TRUE(snn == nn2);
|
|
|
|
}
|
|
|
|
|
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 19:45:47 -05:00
|
|
|
{
|
|
|
|
// not_null -> strict_not_null
|
|
|
|
int x = 42;
|
|
|
|
|
|
|
|
not_null<int*> nn{&x};
|
|
|
|
|
|
|
|
const strict_not_null<int*> snn1{nn};
|
|
|
|
const strict_not_null<int*> snn2{nn};
|
|
|
|
|
|
|
|
strict_helper(nn);
|
|
|
|
strict_helper_const(nn);
|
|
|
|
|
2019-12-04 16:46:50 -05:00
|
|
|
EXPECT_TRUE(snn1 == nn);
|
|
|
|
EXPECT_TRUE(snn2 == nn);
|
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 19:45:47 -05:00
|
|
|
|
|
|
|
std::hash<strict_not_null<int*>> hash_snn;
|
|
|
|
std::hash<not_null<int*>> hash_nn;
|
|
|
|
|
2019-12-04 16:46:50 -05:00
|
|
|
EXPECT_TRUE(hash_nn(snn1) == hash_nn(nn));
|
|
|
|
EXPECT_TRUE(hash_snn(snn1) == hash_nn(nn));
|
|
|
|
EXPECT_TRUE(hash_nn(snn1) == hash_nn(snn2));
|
|
|
|
EXPECT_TRUE(hash_snn(snn1) == hash_snn(nn));
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
2023-02-06 16:16:06 -05:00
|
|
|
{
|
|
|
|
// not_null -> strict_not_null
|
|
|
|
const int x = 42;
|
|
|
|
|
|
|
|
not_null<const int*> nn{&x};
|
|
|
|
|
|
|
|
const strict_not_null<const int*> snn1{nn};
|
|
|
|
const strict_not_null<const int*> snn2{nn};
|
|
|
|
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(!StrictHelperCompilesFor<not_null<const int*>>,
|
|
|
|
"!StrictHelperCompilesFor<not_null<const int*>>");
|
2023-02-06 16:16:06 -05:00
|
|
|
strict_helper_const(nn);
|
|
|
|
|
|
|
|
EXPECT_TRUE(snn1 == nn);
|
|
|
|
EXPECT_TRUE(snn2 == nn);
|
|
|
|
|
|
|
|
std::hash<strict_not_null<const int*>> hash_snn;
|
|
|
|
std::hash<not_null<const int*>> hash_nn;
|
|
|
|
|
|
|
|
EXPECT_TRUE(hash_nn(snn1) == hash_nn(nn));
|
|
|
|
EXPECT_TRUE(hash_snn(snn1) == hash_nn(nn));
|
|
|
|
EXPECT_TRUE(hash_nn(snn1) == hash_nn(snn2));
|
|
|
|
EXPECT_TRUE(hash_snn(snn1) == hash_snn(nn));
|
|
|
|
}
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(__cplusplus) && (__cplusplus >= 201703L)
|
|
|
|
|
2019-12-03 17:32:25 -05:00
|
|
|
TEST(strict_notnull_tests, TestStrictNotNullConstructorTypeDeduction)
|
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 19:45:47 -05:00
|
|
|
{
|
2021-05-20 21:18:08 -04:00
|
|
|
const auto terminateHandler = std::set_terminate([] {
|
2019-12-12 13:55:26 -05:00
|
|
|
std::cerr << "Expected Death. TestStrictNotNullConstructorTypeDeduction";
|
|
|
|
std::abort();
|
|
|
|
});
|
2021-05-20 21:18:08 -04:00
|
|
|
const auto expected = GetExpectedDeathString(terminateHandler);
|
2019-12-12 14:15:41 -05:00
|
|
|
|
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 19:45:47 -05:00
|
|
|
{
|
|
|
|
int i = 42;
|
|
|
|
|
|
|
|
strict_not_null x{&i};
|
|
|
|
helper(strict_not_null{&i});
|
|
|
|
helper_const(strict_not_null{&i});
|
|
|
|
|
2019-12-04 16:46:50 -05:00
|
|
|
EXPECT_TRUE(*x == 42);
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
2023-02-06 16:16:06 -05:00
|
|
|
{
|
|
|
|
const int i = 42;
|
|
|
|
|
|
|
|
strict_not_null x{&i};
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(!HelperCompilesFor<strict_not_null<const int*>>,
|
|
|
|
"!HelperCompilesFor<strict_not_null<const int*>>");
|
2023-02-06 16:16:06 -05:00
|
|
|
helper_const(strict_not_null{&i});
|
|
|
|
|
|
|
|
EXPECT_TRUE(*x == 42);
|
|
|
|
}
|
|
|
|
|
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 19:45:47 -05:00
|
|
|
{
|
|
|
|
int i = 42;
|
|
|
|
int* p = &i;
|
|
|
|
|
|
|
|
strict_not_null x{p};
|
|
|
|
helper(strict_not_null{p});
|
|
|
|
helper_const(strict_not_null{p});
|
|
|
|
|
2019-12-04 16:46:50 -05:00
|
|
|
EXPECT_TRUE(*x == 42);
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
2023-02-06 16:16:06 -05:00
|
|
|
{
|
|
|
|
const int i = 42;
|
|
|
|
const int* p = &i;
|
|
|
|
|
|
|
|
strict_not_null x{p};
|
2025-01-04 12:50:31 -05:00
|
|
|
static_assert(!HelperCompilesFor<strict_not_null<const int*>>,
|
|
|
|
"!HelperCompilesFor<strict_not_null<const int*>>");
|
2023-02-06 16:16:06 -05:00
|
|
|
helper_const(strict_not_null{p});
|
|
|
|
|
|
|
|
EXPECT_TRUE(*x == 42);
|
|
|
|
}
|
|
|
|
|
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 19:45:47 -05:00
|
|
|
{
|
|
|
|
auto workaround_macro = []() {
|
|
|
|
int* p1 = nullptr;
|
|
|
|
const strict_not_null x{p1};
|
|
|
|
};
|
2021-05-20 21:18:08 -04:00
|
|
|
EXPECT_DEATH(workaround_macro(), expected);
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto workaround_macro = []() {
|
|
|
|
const int* p1 = nullptr;
|
|
|
|
const strict_not_null x{p1};
|
|
|
|
};
|
2021-05-20 21:18:08 -04:00
|
|
|
EXPECT_DEATH(workaround_macro(), expected);
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int* p = nullptr;
|
|
|
|
|
2021-05-20 21:18:08 -04:00
|
|
|
EXPECT_DEATH(helper(strict_not_null{p}), expected);
|
|
|
|
EXPECT_DEATH(helper_const(strict_not_null{p}), expected);
|
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 19:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
|
|
|
{
|
|
|
|
strict_not_null x{nullptr};
|
|
|
|
helper(strict_not_null{nullptr});
|
|
|
|
helper_const(strict_not_null{nullptr});
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif // #if defined(__cplusplus) && (__cplusplus >= 201703L)
|