Skip to content

Commit 0d80f44

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

File tree

6 files changed

+141
-3
lines changed

6 files changed

+141
-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 71c42c00d988871b3ccbd5fc1a8335f87979bc98
26+
#define OUTCOME_PREVIOUS_COMMIT_DATE "2025-10-08 15:19:09 +00:00"
27+
#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 71c42c00
Submodule wg14_result added at 0755209
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
30+
#define WG14_RESULT_ENABLE_HEADER_ONLY 1
31+
32+
#include "../../include/outcome/experimental/wg14_result/include/wg14_result/status_code.h"
33+
#include "../../include/outcome/experimental/wg14_result/include/wg14_result/status_code_generic.h"
34+
35+
#include "../../include/outcome/experimental/status-code/include/status-code/config.hpp"
36+
#include "../../include/outcome/experimental/status-code/include/status-code/status_code_domain.hpp"
37+
#include "../../include/outcome/experimental/status_result.hpp"
38+
39+
#include "quickcpplib/boost/test/unit_test.hpp"
40+
41+
42+
BOOST_OUTCOME_AUTO_TEST_CASE(works / status_code / wg14_status_code, "Tests that the WG14 C status_code works as intended")
43+
{
44+
// The C ones need to be ABI compatible with the C++ ones
45+
static_assert(sizeof(SYSTEM_ERROR2_NAMESPACE::generic_code) == sizeof(WG14_RESULT_PREFIX(status_code_generic)),
46+
"WG14 C status code is not the same size as the C++ status code!");
47+
static_assert(alignof(SYSTEM_ERROR2_NAMESPACE::generic_code) == alignof(WG14_RESULT_PREFIX(status_code_generic)),
48+
"WG14 C status code is not the same alignment as the C++ status code!");
49+
static_assert(sizeof(SYSTEM_ERROR2_NAMESPACE::status_code_domain) == sizeof(WG14_RESULT_PREFIX(status_code_domain)),
50+
"WG14 C status code domain is not the same size as the C++ status code domain!");
51+
static_assert(alignof(SYSTEM_ERROR2_NAMESPACE::status_code_domain) == alignof(WG14_RESULT_PREFIX(status_code_domain)),
52+
"WG14 C status code domain is not the same alignment as the C++ status code domain!");
53+
static_assert(sizeof(SYSTEM_ERROR2_NAMESPACE::status_code_domain::string_ref) == sizeof(WG14_RESULT_PREFIX(status_code_domain_string_ref)),
54+
"WG14 C status code domain string ref is not the same size as the C++ status code domain string ref!");
55+
static_assert(alignof(SYSTEM_ERROR2_NAMESPACE::status_code_domain::string_ref) == alignof(WG14_RESULT_PREFIX(status_code_domain_string_ref)),
56+
"WG14 C status code domain string ref is not the same alignment as the C++ status code domain string ref!");
57+
58+
// Construct with C edition, use with C++ edition
59+
{
60+
WG14_RESULT_CONSTEXPR_OR_CONST WG14_RESULT_PREFIX(status_code_generic)
61+
empty1 = {{WG14_RESULT_NULLPTR}, WG14_RESULT_PREFIX(status_code_errc_success)},
62+
success1 = WG14_RESULT_PREFIX(status_code_generic_make)(WG14_RESULT_PREFIX(status_code_errc_success)),
63+
failure1 = WG14_RESULT_PREFIX(status_code_generic_make)(WG14_RESULT_PREFIX(status_code_errc_permission_denied));
64+
BOOST_CHECK(status_code_is_empty(empty1));
65+
BOOST_CHECK(!status_code_is_empty(success1));
66+
BOOST_CHECK(!status_code_is_empty(failure1));
67+
BOOST_CHECK(status_code_is_success(success1));
68+
BOOST_CHECK(status_code_is_failure(failure1));
69+
printf("generic_code empty has value %d (%s) is success %d is failure %d\n", empty1.value, status_code_message(empty1).c_str,
70+
status_code_is_success(empty1), status_code_is_failure(empty1));
71+
printf("generic_code success has value %d (%s) is success %d is failure %d\n", success1.value, status_code_message(success1).c_str,
72+
status_code_is_success(success1), status_code_is_failure(success1));
73+
printf("generic_code failure has value %d (%s) is success %d is failure %d\n", failure1.value, status_code_message(failure1).c_str,
74+
status_code_is_success(failure1), status_code_is_failure(failure1));
75+
76+
#if !QUICKCPPLIB_IN_UNDEFINED_SANITIZER
77+
// For obvious reasons, ubsan really doesn't like C manufactured vptrs
78+
const SYSTEM_ERROR2_NAMESPACE::generic_code *empty1a = (const SYSTEM_ERROR2_NAMESPACE::generic_code *) &empty1,
79+
*success1a = (const SYSTEM_ERROR2_NAMESPACE::generic_code *) &success1,
80+
*failure1a = (const SYSTEM_ERROR2_NAMESPACE::generic_code *) &failure1;
81+
BOOST_CHECK(empty1a->empty());
82+
BOOST_CHECK(!success1a->empty());
83+
BOOST_CHECK(!failure1a->empty());
84+
BOOST_CHECK(success1a->success());
85+
BOOST_CHECK(failure1a->failure());
86+
printf("generic_code empty has value %d (%s) is success %d is failure %d\n", (int) empty1a->value(), empty1a->message().c_str(), empty1a->success(),
87+
empty1a->failure());
88+
printf("generic_code success has value %d (%s) is success %d is failure %d\n", (int) success1a->value(), success1a->message().c_str(), success1a->success(),
89+
success1a->failure());
90+
printf("generic_code failure has value %d (%s) is success %d is failure %d\n", (int) failure1a->value(), failure1a->message().c_str(), failure1a->success(),
91+
failure1a->failure());
92+
#endif
93+
}
94+
95+
// Construct with C++ edition, use with C edition
96+
{
97+
constexpr SYSTEM_ERROR2_NAMESPACE::generic_code empty1, success1(SYSTEM_ERROR2_NAMESPACE::errc::success),
98+
failure1(SYSTEM_ERROR2_NAMESPACE::errc::permission_denied);
99+
BOOST_CHECK(empty1.empty());
100+
BOOST_CHECK(!success1.empty());
101+
BOOST_CHECK(!failure1.empty());
102+
BOOST_CHECK(success1.success());
103+
BOOST_CHECK(failure1.failure());
104+
printf("generic_code empty has value %d (%s) is success %d is failure %d\n", static_cast<int>(empty1.value()), empty1.message().c_str(),
105+
static_cast<int>(empty1.success()), static_cast<int>(empty1.failure()));
106+
printf("generic_code success has value %d (%s) is success %d is failure %d\n", static_cast<int>(success1.value()), success1.message().c_str(),
107+
static_cast<int>(success1.success()), static_cast<int>(success1.failure()));
108+
printf("generic_code failure has value %d (%s) is success %d is failure %d\n", static_cast<int>(failure1.value()), failure1.message().c_str(),
109+
static_cast<int>(failure1.success()), static_cast<int>(failure1.failure()));
110+
111+
const WG14_RESULT_PREFIX(status_code_generic) &empty1a = *(const WG14_RESULT_PREFIX(status_code_generic) *) &empty1,
112+
&success1a = *(const WG14_RESULT_PREFIX(status_code_generic) *) &success1,
113+
&failure1a = *(const WG14_RESULT_PREFIX(status_code_generic) *) &failure1;
114+
BOOST_CHECK(status_code_is_empty(empty1a));
115+
BOOST_CHECK(!status_code_is_empty(success1a));
116+
BOOST_CHECK(!status_code_is_empty(failure1a));
117+
BOOST_CHECK(status_code_is_success(success1a));
118+
BOOST_CHECK(status_code_is_failure(failure1a));
119+
printf("generic_code empty has value %d (%s) is success %d is failure %d\n", empty1a.value, status_code_message(empty1a).c_str,
120+
status_code_is_success(empty1a), status_code_is_failure(empty1a));
121+
printf("generic_code success has value %d (%s) is success %d is failure %d\n", success1a.value, status_code_message(success1a).c_str,
122+
status_code_is_success(success1a), status_code_is_failure(success1a));
123+
printf("generic_code failure has value %d (%s) is success %d is failure %d\n", failure1a.value, status_code_message(failure1a).c_str,
124+
status_code_is_success(failure1a), status_code_is_failure(failure1a));
125+
}
126+
}
127+
#else
128+
int main(void)
129+
{
130+
return 0;
131+
}
132+
#endif

0 commit comments

Comments
 (0)