Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions stl/inc/optional
Original file line number Diff line number Diff line change
Expand Up @@ -338,22 +338,40 @@ public:

// observers [optional.object.observe]
_NODISCARD constexpr const _Ty* operator->() const {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(this->_Has_value, "Cannot access value of empty optional");
#endif // _CONTAINER_DEBUG_LEVEL > 0
return _STD addressof(this->_Value);
}
_NODISCARD constexpr _Ty* operator->() {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(this->_Has_value, "Cannot access value of empty optional");
#endif // _CONTAINER_DEBUG_LEVEL > 0
return _STD addressof(this->_Value);
}

_NODISCARD constexpr const _Ty& operator*() const& {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(this->_Has_value, "Cannot access value of empty optional");
#endif // _CONTAINER_DEBUG_LEVEL > 0
return this->_Value;
}
_NODISCARD constexpr _Ty& operator*() & {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(this->_Has_value, "Cannot access value of empty optional");
#endif // _CONTAINER_DEBUG_LEVEL > 0
return this->_Value;
}
_NODISCARD constexpr _Ty&& operator*() && {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(this->_Has_value, "Cannot access value of empty optional");
#endif // _CONTAINER_DEBUG_LEVEL > 0
return _STD move(this->_Value);
}
_NODISCARD constexpr const _Ty&& operator*() const&& {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(this->_Has_value, "Cannot access value of empty optional");
#endif // _CONTAINER_DEBUG_LEVEL > 0
return _STD move(this->_Value);
}

Expand Down
9 changes: 5 additions & 4 deletions tests/std/include/test_death.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <test_windows.hpp>

namespace std_testing {

constexpr int internal_failure = 103;
using normal_function_t = void (*)();
using death_function_t = void (*)();
Expand All @@ -23,7 +22,6 @@ namespace std_testing {
abort();
}


class death_test_executive {
const normal_function_t run_normal_tests;
std::vector<death_function_t> death_tests;
Expand Down Expand Up @@ -98,10 +96,11 @@ namespace std_testing {
}

public:
death_test_executive() : run_normal_tests(nullptr) {}

explicit death_test_executive(const normal_function_t normal_tests_function)
: run_normal_tests(normal_tests_function) {}


template <size_t TestsCount>
void add_death_tests(const death_function_t (&tests)[TestsCount]) {
death_tests.insert(death_tests.end(), tests, std::end(tests));
Expand All @@ -111,7 +110,9 @@ namespace std_testing {
if (argc == 1) {
// first pass, run normal tests and sub-process loop
printf("running normal tests...");
run_normal_tests();
if (run_normal_tests != nullptr) {
run_normal_tests();
}
puts(" passed!");

::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ tests\P0202R3_constexpr_algorithm_and_exchange
tests\P0218R1_filesystem
tests\P0220R1_any
tests\P0220R1_optional
tests\P0220R1_optional_death
tests\P0220R1_polymorphic_memory_resources
tests\P0220R1_sample
tests\P0220R1_searchers
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P0220R1_optional_death/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_17_winsdk_matrix.lst
60 changes: 60 additions & 0 deletions tests/std/tests/P0220R1_optional_death/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _CONTAINER_DEBUG_LEVEL 1

#include <optional>
#include <utility>

#include <test_death.hpp>

using namespace std;

struct S {
int value;
};

void test_nullopt_operator_arrow() {
optional<S> o;
(void) o->value;
}

void test_nullopt_operator_arrow_const() {
const optional<S> o;
(void) o->value;
}

void test_nullopt_operator_star_lvalue() {
optional<S> o;
(void) *o;
}

void test_nullopt_operator_star_const_lvalue() {
const optional<S> o;
(void) *o;
}

void test_nullopt_operator_star_rvalue() {
optional<S> o;
(void) *move(o);
}

void test_nullopt_operator_star_const_rvalue() {
const optional<S> o;
(void) *move(o);
}

int main(int argc, char* argv[]) {
std_testing::death_test_executive exec;

exec.add_death_tests({
test_nullopt_operator_arrow,
test_nullopt_operator_arrow_const,
test_nullopt_operator_star_lvalue,
test_nullopt_operator_star_const_lvalue,
test_nullopt_operator_star_rvalue,
test_nullopt_operator_star_const_rvalue,
});

return exec.run(argc, argv);
}
2 changes: 1 addition & 1 deletion tests/std/tests/P0660R10_stop_token_death/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void test_case_throw_during_request_stop() {
}

int main(int argc, char* argv[]) {
std_testing::death_test_executive exec([] {});
std_testing::death_test_executive exec;

exec.add_death_tests({
test_case_throw_during_request_stop,
Expand Down
2 changes: 1 addition & 1 deletion tests/std/tests/P0896R4_common_iterator_death/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void test_case_iter_swap_sentinel_right_valueless() {
}

int main(int argc, char* argv[]) {
std_testing::death_test_executive exec([] {});
std_testing::death_test_executive exec;

#if _ITERATOR_DEBUG_LEVEL != 0
exec.add_death_tests({
Expand Down
2 changes: 1 addition & 1 deletion tests/std/tests/P0896R4_counted_iterator_death/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void test_case_operator_spaceship_incompatible_value_initialized() {
}

int main(int argc, char* argv[]) {
std_testing::death_test_executive exec([] {});
std_testing::death_test_executive exec;

#if _ITERATOR_DEBUG_LEVEL != 0
exec.add_death_tests({
Expand Down
2 changes: 1 addition & 1 deletion tests/std/tests/P0896R4_views_filter_death/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void test_iter_swap_value_initialized_iterator_right() {
}

int main(int argc, char* argv[]) {
std_testing::death_test_executive exec([] {});
std_testing::death_test_executive exec;

#if _ITERATOR_DEBUG_LEVEL != 0
exec.add_death_tests({
Expand Down
2 changes: 1 addition & 1 deletion tests/std/tests/P0896R4_views_transform_death/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void test_flipped_sentinel_difference_value_initialized() {
}

int main(int argc, char* argv[]) {
std_testing::death_test_executive exec([] {});
std_testing::death_test_executive exec;

#if _ITERATOR_DEBUG_LEVEL != 0
exec.add_death_tests({
Expand Down