Skip to content

Commit 084db46

Browse files
committed
Add WG14 reference C reimplementation of Outcome.
1 parent 71c42c0 commit 084db46

File tree

6 files changed

+144
-3
lines changed

6 files changed

+144
-3
lines changed

.boostify

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ include_files = [
1010
]
1111
exclude_files = [
1212
r'.*quickcpplib.*',
13+
r'.*wg14.result.*',
1314
r'^include/outcome/experimental/status-code/(?!include)',
1415
r'^include/outcome.ixx',
1516
r'.*\.natvis$',

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
branch = master
1919
fetchRecurseSubmodules = true
2020
ignore = untracked
21+
[submodule "include/outcome/experimental/wg14_result"]
22+
path = include/outcome/experimental/wg14_result
23+
url = https://github.com/ned14/wg14_result.git

cmake/tests.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(outcome_TESTS
1313
"test/tests/experimental-core-outcome-status.cpp"
1414
"test/tests/experimental-core-result-status.cpp"
1515
"test/tests/experimental-p0709a.cpp"
16+
"test/tests/experimental-wg14-result.cpp"
1617
"test/tests/fileopen.cpp"
1718
"test/tests/hooks.cpp"
1819
"test/tests/issue0007.cpp"

include/outcome/detail/revision.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ Distributed under the Boost Software License, Version 1.0.
2222
*/
2323

2424
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
25-
#define OUTCOME_PREVIOUS_COMMIT_REF 744da6b7536f2850df972ab01504e3c4d9530149
26-
#define OUTCOME_PREVIOUS_COMMIT_DATE "2025-05-21 12:10:22 +00:00"
27-
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 744da6b7
25+
#define OUTCOME_PREVIOUS_COMMIT_REF 0d80f449b2649e2f8e2fe2dea9204e19016ca2f0
26+
#define OUTCOME_PREVIOUS_COMMIT_DATE "2025-10-28 19:12:44 +00:00"
27+
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 0d80f449
Submodule wg14_result added at e924527
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/* Unit testing for outcomes
2+
(C) 2013-2025 Niall Douglas <http://www.nedproductions.biz/> (8 commits)
3+
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License in the accompanying file
8+
Licence.txt or at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
19+
Distributed under the Boost Software License, Version 1.0.
20+
(See accompanying file Licence.txt or copy at
21+
http://www.boost.org/LICENSE_1_0.txt)
22+
*/
23+
24+
#ifndef SYSTEM_ERROR2_NOT_POSIX
25+
26+
#ifdef __GNUC__
27+
#pragma GCC diagnostic ignored "-Wunused-function"
28+
#endif
29+
#ifdef _MSC_VER
30+
#pragma warning(disable : 4505) // unreferenced function has been removed
31+
#endif
32+
33+
#define WG14_RESULT_ENABLE_HEADER_ONLY 1
34+
35+
#include "../../include/outcome/experimental/wg14_result/include/wg14_result/status_code.h"
36+
#include "../../include/outcome/experimental/wg14_result/include/wg14_result/status_code_generic.h"
37+
38+
#include "../../include/outcome/experimental/status-code/include/status-code/config.hpp"
39+
#include "../../include/outcome/experimental/status-code/include/status-code/status_code_domain.hpp"
40+
#include "../../include/outcome/experimental/status_result.hpp"
41+
42+
#include "quickcpplib/boost/test/unit_test.hpp"
43+
44+
45+
BOOST_OUTCOME_AUTO_TEST_CASE(works / status_code / wg14_status_code, "Tests that the WG14 C status_code works as intended")
46+
{
47+
// The C ones need to be ABI compatible with the C++ ones
48+
static_assert(sizeof(SYSTEM_ERROR2_NAMESPACE::generic_code) == sizeof(WG14_RESULT_PREFIX(status_code_generic)),
49+
"WG14 C status code is not the same size as the C++ status code!");
50+
static_assert(alignof(SYSTEM_ERROR2_NAMESPACE::generic_code) == alignof(WG14_RESULT_PREFIX(status_code_generic)),
51+
"WG14 C status code is not the same alignment as the C++ status code!");
52+
static_assert(sizeof(SYSTEM_ERROR2_NAMESPACE::status_code_domain) == sizeof(WG14_RESULT_PREFIX(status_code_domain)),
53+
"WG14 C status code domain is not the same size as the C++ status code domain!");
54+
static_assert(alignof(SYSTEM_ERROR2_NAMESPACE::status_code_domain) == alignof(WG14_RESULT_PREFIX(status_code_domain)),
55+
"WG14 C status code domain is not the same alignment as the C++ status code domain!");
56+
static_assert(sizeof(SYSTEM_ERROR2_NAMESPACE::status_code_domain::string_ref) == sizeof(WG14_RESULT_PREFIX(status_code_domain_string_ref)),
57+
"WG14 C status code domain string ref is not the same size as the C++ status code domain string ref!");
58+
static_assert(alignof(SYSTEM_ERROR2_NAMESPACE::status_code_domain::string_ref) == alignof(WG14_RESULT_PREFIX(status_code_domain_string_ref)),
59+
"WG14 C status code domain string ref is not the same alignment as the C++ status code domain string ref!");
60+
61+
// Construct with C edition, use with C++ edition
62+
{
63+
WG14_RESULT_CONSTEXPR_OR_CONST WG14_RESULT_PREFIX(status_code_generic)
64+
empty1 = {{WG14_RESULT_NULLPTR}, WG14_RESULT_PREFIX(status_code_errc_success)},
65+
success1 = WG14_RESULT_PREFIX(status_code_generic_make)(WG14_RESULT_PREFIX(status_code_errc_success)),
66+
failure1 = WG14_RESULT_PREFIX(status_code_generic_make)(WG14_RESULT_PREFIX(status_code_errc_permission_denied));
67+
BOOST_CHECK(status_code_is_empty(empty1));
68+
BOOST_CHECK(!status_code_is_empty(success1));
69+
BOOST_CHECK(!status_code_is_empty(failure1));
70+
BOOST_CHECK(status_code_is_success(success1));
71+
BOOST_CHECK(status_code_is_failure(failure1));
72+
printf("generic_code empty has value %d (%s) is success %d is failure %d\n", empty1.value, status_code_message(empty1).c_str,
73+
status_code_is_success(empty1), status_code_is_failure(empty1));
74+
printf("generic_code success has value %d (%s) is success %d is failure %d\n", success1.value, status_code_message(success1).c_str,
75+
status_code_is_success(success1), status_code_is_failure(success1));
76+
printf("generic_code failure has value %d (%s) is success %d is failure %d\n", failure1.value, status_code_message(failure1).c_str,
77+
status_code_is_success(failure1), status_code_is_failure(failure1));
78+
79+
#if !QUICKCPPLIB_IN_UNDEFINED_SANITIZER
80+
// For obvious reasons, ubsan really doesn't like C manufactured vptrs
81+
const SYSTEM_ERROR2_NAMESPACE::generic_code *empty1a = (const SYSTEM_ERROR2_NAMESPACE::generic_code *) &empty1,
82+
*success1a = (const SYSTEM_ERROR2_NAMESPACE::generic_code *) &success1,
83+
*failure1a = (const SYSTEM_ERROR2_NAMESPACE::generic_code *) &failure1;
84+
BOOST_CHECK(empty1a->empty());
85+
BOOST_CHECK(!success1a->empty());
86+
BOOST_CHECK(!failure1a->empty());
87+
BOOST_CHECK(success1a->success());
88+
BOOST_CHECK(failure1a->failure());
89+
printf("generic_code empty has value %d (%s) is success %d is failure %d\n", (int) empty1a->value(), empty1a->message().c_str(), empty1a->success(),
90+
empty1a->failure());
91+
printf("generic_code success has value %d (%s) is success %d is failure %d\n", (int) success1a->value(), success1a->message().c_str(), success1a->success(),
92+
success1a->failure());
93+
printf("generic_code failure has value %d (%s) is success %d is failure %d\n", (int) failure1a->value(), failure1a->message().c_str(), failure1a->success(),
94+
failure1a->failure());
95+
#endif
96+
}
97+
98+
// Construct with C++ edition, use with C edition
99+
{
100+
constexpr SYSTEM_ERROR2_NAMESPACE::generic_code empty1, success1(SYSTEM_ERROR2_NAMESPACE::errc::success),
101+
failure1(SYSTEM_ERROR2_NAMESPACE::errc::permission_denied);
102+
BOOST_CHECK(empty1.empty());
103+
BOOST_CHECK(!success1.empty());
104+
BOOST_CHECK(!failure1.empty());
105+
BOOST_CHECK(success1.success());
106+
BOOST_CHECK(failure1.failure());
107+
printf("generic_code empty has value %d (%s) is success %d is failure %d\n", static_cast<int>(empty1.value()), empty1.message().c_str(),
108+
static_cast<int>(empty1.success()), static_cast<int>(empty1.failure()));
109+
printf("generic_code success has value %d (%s) is success %d is failure %d\n", static_cast<int>(success1.value()), success1.message().c_str(),
110+
static_cast<int>(success1.success()), static_cast<int>(success1.failure()));
111+
printf("generic_code failure has value %d (%s) is success %d is failure %d\n", static_cast<int>(failure1.value()), failure1.message().c_str(),
112+
static_cast<int>(failure1.success()), static_cast<int>(failure1.failure()));
113+
114+
const WG14_RESULT_PREFIX(status_code_generic) &empty1a = *(const WG14_RESULT_PREFIX(status_code_generic) *) &empty1,
115+
&success1a = *(const WG14_RESULT_PREFIX(status_code_generic) *) &success1,
116+
&failure1a = *(const WG14_RESULT_PREFIX(status_code_generic) *) &failure1;
117+
BOOST_CHECK(status_code_is_empty(empty1a));
118+
BOOST_CHECK(!status_code_is_empty(success1a));
119+
BOOST_CHECK(!status_code_is_empty(failure1a));
120+
BOOST_CHECK(status_code_is_success(success1a));
121+
BOOST_CHECK(status_code_is_failure(failure1a));
122+
printf("generic_code empty has value %d (%s) is success %d is failure %d\n", empty1a.value, status_code_message(empty1a).c_str,
123+
status_code_is_success(empty1a), status_code_is_failure(empty1a));
124+
printf("generic_code success has value %d (%s) is success %d is failure %d\n", success1a.value, status_code_message(success1a).c_str,
125+
status_code_is_success(success1a), status_code_is_failure(success1a));
126+
printf("generic_code failure has value %d (%s) is success %d is failure %d\n", failure1a.value, status_code_message(failure1a).c_str,
127+
status_code_is_success(failure1a), status_code_is_failure(failure1a));
128+
}
129+
}
130+
#else
131+
int main(void)
132+
{
133+
return 0;
134+
}
135+
#endif

0 commit comments

Comments
 (0)