diff --git a/doc/src/content/experimental/c-api/from-c/_index.md b/doc/src/content/experimental/c-api/from-c/_index.md index 737c457615..000f67f338 100644 --- a/doc/src/content/experimental/c-api/from-c/_index.md +++ b/doc/src/content/experimental/c-api/from-c/_index.md @@ -11,7 +11,8 @@ The C macro API header `` has some macros for wor
Declares to C a basic_result type uniquely identified by ident. T is available at the member variable .value, and E is available -at the member variable .error. +at the member variable .error. If you call this from within +C++, make SURE it is not within a extern "C" block!
CXX_RESULT(ident)
A reference to a previously declared result type with diff --git a/doc/src/content/experimental/c-api/from-c/system_code.md b/doc/src/content/experimental/c-api/from-c/system_code.md index 36d644e615..964c91dc59 100644 --- a/doc/src/content/experimental/c-api/from-c/system_code.md +++ b/doc/src/content/experimental/c-api/from-c/system_code.md @@ -25,7 +25,8 @@ identified by ident. T is available at the member variable .value, and struct cxx_status_code_system is available at the member variable .error. If in C++, implements C extern functions for making successful and failure results -of this type. +of this type. If you call this from within +C++, make SURE it is not within a extern "C" block!
CXX_RESULT_SYSTEM(ident)
A reference to a previously declared status_result type with diff --git a/include/outcome/detail/revision.hpp b/include/outcome/detail/revision.hpp index 79107be4cc..c936c1c6da 100644 --- a/include/outcome/detail/revision.hpp +++ b/include/outcome/detail/revision.hpp @@ -22,6 +22,6 @@ Distributed under the Boost Software License, Version 1.0. */ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define OUTCOME_PREVIOUS_COMMIT_REF 10eb45ca7d11a35df14e0fa89939a3e3185c0aa9 -#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-16 20:39:50 +00:00" -#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 10eb45ca +#define OUTCOME_PREVIOUS_COMMIT_REF e30438653a080acf5929c35c7802d40824dbae9b +#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 23:08:38 +00:00" +#define OUTCOME_PREVIOUS_COMMIT_UNIQUE e3043865 diff --git a/include/outcome/experimental/result.h b/include/outcome/experimental/result.h index b9d9b5e6d9..61682b94f5 100644 --- a/include/outcome/experimental/result.h +++ b/include/outcome/experimental/result.h @@ -25,15 +25,52 @@ Distributed under the Boost Software License, Version 1.0. #ifndef OUTCOME_EXPERIMENTAL_RESULT_H #define OUTCOME_EXPERIMENTAL_RESULT_H +#include #include // for size_t #include // for intptr_t #include "../detail/try.h" -#if __STDC_VERSION__ >= 199900L -#define OUTCOME_C_INLINE inline +#ifndef OUTCOME_C_WEAK +#ifdef _MSC_VER +#define OUTCOME_C_WEAK inline #else -#define OUTCOME_C_INLINE +#define OUTCOME_C_WEAK __attribute__((weak)) +#endif +#endif + +#ifndef OUTCOME_C_MSVC_FORCE_EMIT +#ifdef _MSC_VER +#ifdef __cplusplus +#define OUTCOME_C_MSVC_FORCE_EMIT(x) extern "C" __declspec(selectany) void *x##_emit = x; +#else +#define OUTCOME_C_MSVC_FORCE_EMIT(x) extern __declspec(selectany) void *x##_emit = x; +#endif +#else +#define OUTCOME_C_MSVC_FORCE_EMIT(x) +#endif +#endif + + +#ifndef OUTCOME_C_NODISCARD +#if __STDC_VERSION__ >= 202000L || __cplusplus >= 201700L +#define OUTCOME_C_NODISCARD [[nodiscard]] +#ifdef __cplusplus +#define OUTCOME_C_NODISCARD_EXTERN_C extern "C" [[nodiscard]] +#else +#define OUTCOME_C_NODISCARD_EXTERN_C [[nodiscard]] extern +#endif +#elif defined(__GNUC__) || defined(__clang__) +#define OUTCOME_C_NODISCARD __attribute__((warn_unused_result)) +#ifdef __cplusplus +#define OUTCOME_C_NODISCARD_EXTERN_C extern "C" __attribute__((warn_unused_result)) +#else +#define OUTCOME_C_NODISCARD_EXTERN_C extern __attribute__((warn_unused_result)) +#endif +#else +#define OUTCOME_C_NODISCARD +#define OUTCOME_C_NODISCARD_EXTERN_C extern +#endif #endif #include "../outcome_gdb.h" @@ -74,9 +111,9 @@ extern "C" #define CXX_STATUS_CODE(ident) struct cxx_status_code_##ident - extern void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes); - extern void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode); - extern void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode); + extern OUTCOME_C_WEAK void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes); + extern OUTCOME_C_WEAK void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode); + extern OUTCOME_C_WEAK void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode); extern int outcome_status_code_equal(const void *a, const void *b); extern int outcome_status_code_equal_generic(const void *a, int errcode); extern const char *outcome_status_code_message(const void *a); @@ -105,7 +142,7 @@ extern "C" pun.c = v; \ return std::move(pun.cpp); \ } \ - inline cxx_result_status_code_##ident to_##ident(OUTCOME_V2_NAMESPACE::experimental::status_result v) \ + OUTCOME_C_NODISCARD inline cxx_result_status_code_##ident to_##ident(OUTCOME_V2_NAMESPACE::experimental::status_result v) \ { \ union type_punner_t \ { \ @@ -132,25 +169,31 @@ extern "C" unsigned flags; \ S error; \ }; \ - static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_success(R value) \ + OUTCOME_C_NODISCARD_EXTERN_C OUTCOME_C_WEAK struct cxx_result_status_code_##ident outcome_make_result_##ident##_success(R value) \ { \ struct cxx_result_status_code_##ident ret; \ + assert(outcome_make_result_status_code_success); /* If this fails, you need to compile this file at least once in C++. */ \ outcome_make_result_status_code_success((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), (const void *) &value, \ sizeof(value)); \ return ret; \ } \ - static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_posix(int errcode) \ + OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_success) \ + OUTCOME_C_NODISCARD_EXTERN_C OUTCOME_C_WEAK struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_posix(int errcode) \ { \ struct cxx_result_status_code_##ident ret; \ + assert(outcome_make_result_status_code_failure_posix); /* If this fails, you need to compile this file at least once in C++. */ \ outcome_make_result_status_code_failure_posix((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), errcode); \ return ret; \ } \ - static OUTCOME_C_INLINE struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_system(intptr_t errcode) \ + OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_posix) \ + OUTCOME_C_NODISCARD_EXTERN_C OUTCOME_C_WEAK struct cxx_result_status_code_##ident outcome_make_result_##ident##_failure_system(intptr_t errcode) \ { \ struct cxx_result_status_code_##ident ret; \ + assert(outcome_make_result_status_code_failure_system); /* If this fails, you need to compile this file at least once in C++. */ \ outcome_make_result_status_code_failure_system((void *) &ret, sizeof(ret), offsetof(struct cxx_result_status_code_##ident, flags), errcode); \ return ret; \ } \ + OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_system) \ CXX_DECLARE_RESULT_STATUS_CODE_CXX(ident, R, S) #define CXX_RESULT_STATUS_CODE(ident) struct cxx_result_status_code_##ident @@ -223,7 +266,7 @@ extern "C" #ifndef __cplusplus // Declares the function in C, needs to occur at least once in a C++ source file to get implemented #define CXX_DECLARE_RESULT_SYSTEM_FROM_ENUM(ident, enum_name, uuid, ...) \ - extern struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v); + OUTCOME_C_NODISCARD_EXTERN_C struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v); #else } @@ -241,8 +284,13 @@ extern "C" #include #include +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + // You need to include this C header in at least one C++ source file to have these C helper functions be implemented -extern "C" inline void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes) +extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_success(void *out, size_t bytes, size_t offset, const void *toset, size_t tosetbytes) { union type_punner_t { @@ -267,8 +315,9 @@ extern "C" inline void outcome_make_result_status_code_success(void *out, size_t memcpy(out, toset, tosetbytes); memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy); } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_success) -extern "C" inline void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode) +extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_failure_posix(void *out, size_t bytes, size_t offset, int errcode) { using value_type = OUTCOME_V2_NAMESPACE::experimental::posix_code::value_type; union type_punner_t @@ -294,8 +343,9 @@ extern "C" inline void outcome_make_result_status_code_failure_posix(void *out, memcpy(out, (void *) &pun.c, sizeof(value_type)); memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy); } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_failure_posix) -extern "C" inline void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode) +extern "C" OUTCOME_C_WEAK void outcome_make_result_status_code_failure_system(void *out, size_t bytes, size_t offset, intptr_t errcode) { using value_type = OUTCOME_V2_NAMESPACE::experimental::system_code::value_type; union type_punner_t @@ -315,9 +365,9 @@ extern "C" inline void outcome_make_result_status_code_failure_system(void *out, ~type_punner_t() {} } pun{ #ifdef _WIN32 - OUTCOME_V2_NAMESPACE::experimental::win32_code(errcode) + OUTCOME_V2_NAMESPACE::experimental::win32_code((OUTCOME_V2_NAMESPACE::experimental::win32::DWORD) errcode) #else - OUTCOME_V2_NAMESPACE::experimental::posix_code(errcode) + OUTCOME_V2_NAMESPACE::experimental::posix_code((int) errcode) #endif }; static_assert(sizeof(pun.cpp) == sizeof(pun.c), ""); @@ -327,27 +377,31 @@ extern "C" inline void outcome_make_result_status_code_failure_system(void *out, memcpy(out, (void *) &pun.c, sizeof(value_type)); memcpy((void *) ((char *) out + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy); } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_status_code_failure_system) -extern "C" inline int outcome_status_code_equal(const void *_a, const void *_b) +extern "C" OUTCOME_C_WEAK int outcome_status_code_equal(const void *_a, const void *_b) { const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a; const auto *b = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _b; return *a == *b; } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_equal) -extern "C" inline int outcome_status_code_equal_generic(const void *_a, int errcode) +extern "C" OUTCOME_C_WEAK int outcome_status_code_equal_generic(const void *_a, int errcode) { const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a; return *a == (SYSTEM_ERROR2_NAMESPACE::errc) errcode; } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_equal_generic) -extern "C" inline const char *outcome_status_code_message(const void *_a) +extern "C" OUTCOME_C_WEAK const char *outcome_status_code_message(const void *_a) { static thread_local SYSTEM_ERROR2_NAMESPACE::system_code::string_ref msg((const char *) nullptr, 0); const auto *a = (const SYSTEM_ERROR2_NAMESPACE::system_code *) _a; msg = a->message(); return msg.c_str(); } +OUTCOME_C_MSVC_FORCE_EMIT(outcome_status_code_message) OUTCOME_V2_NAMESPACE_BEGIN namespace experimental @@ -383,8 +437,8 @@ namespace experimental memcpy((void *) ((char *) &ret + offset), (const void *) ((const char *) &pun.c + punoffset), tocopy); return ret; } - } -} + } // namespace detail +} // namespace experimental OUTCOME_V2_NAMESPACE_END // Unique UUID for the enum PLEASE use https://www.random.org/cgi-bin/randbyte?nbytes=16&format=h @@ -402,10 +456,16 @@ OUTCOME_V2_NAMESPACE_END } \ }; \ SYSTEM_ERROR2_NAMESPACE_END \ - extern "C" inline struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name(enum enum_name v) \ + extern "C" OUTCOME_C_NODISCARD OUTCOME_C_WEAK struct cxx_result_status_code_system_##ident outcome_make_result_##ident##_failure_system_enum_##enum_name( \ + enum enum_name v) \ { \ return OUTCOME_V2_NAMESPACE::experimental::detail::outcome_make_result_failure_system_enum(v); \ - } + } \ + OUTCOME_C_MSVC_FORCE_EMIT(outcome_make_result_##ident##_failure_system_enum_##enum_name) + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif #endif diff --git a/include/outcome/outcome_gdb.h b/include/outcome/outcome_gdb.h index 8b022e01ec..e0f8a37fbf 100644 --- a/include/outcome/outcome_gdb.h +++ b/include/outcome/outcome_gdb.h @@ -27,6 +27,10 @@ Distributed under the Boost Software License, Version 1.0. #ifndef OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS #if defined(__ELF__) +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Woverlength-strings" +#endif __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n" ".byte 4 /* Python Text */\n" ".ascii \"gdb.inlined-script\\n\"\n" @@ -149,6 +153,9 @@ __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n" ".byte 0\n" ".popsection\n"); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif #endif #endif diff --git a/single-header/outcome-basic.hpp b/single-header/outcome-basic.hpp index a31f547567..6846f92d30 100644 --- a/single-header/outcome-basic.hpp +++ b/single-header/outcome-basic.hpp @@ -1019,9 +1019,9 @@ Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt) */ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define OUTCOME_PREVIOUS_COMMIT_REF 5bcd0f32f28659a0eab62f1d643d878c2220788d -#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-15 17:46:44 +00:00" -#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 5bcd0f32 +#define OUTCOME_PREVIOUS_COMMIT_REF b01ac71096775daf18d9a57a69be5e129f421a67 +#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 20:54:50 +00:00" +#define OUTCOME_PREVIOUS_COMMIT_UNIQUE b01ac710 #define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)) #ifdef _DEBUG #define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d))) @@ -3927,6 +3927,10 @@ Distributed under the Boost Software License, Version 1.0. #define OUTCOME_INLINE_GDB_PRETTY_PRINTER_H #ifndef OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS #if defined(__ELF__) +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Woverlength-strings" +#endif __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n" ".byte 4 /* Python Text */\n" ".ascii \"gdb.inlined-script\\n\"\n" @@ -4028,6 +4032,9 @@ __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n" ".ascii \"register_printers(gdb.current_objfile())\\n\"\n" ".byte 0\n" ".popsection\n"); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif #endif #endif #endif @@ -6334,6 +6341,88 @@ Distributed under the Boost Software License, Version 1.0. */ #ifndef OUTCOME_TRY_HPP #define OUTCOME_TRY_HPP +/* Try operation macros +(C) 2017-2024 Niall Douglas (20 commits) +File Created: July 2017 + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License in the accompanying file +Licence.txt or at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Distributed under the Boost Software License, Version 1.0. + (See accompanying file Licence.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef OUTCOME_TRY_H +#define OUTCOME_TRY_H +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wparentheses" +#endif +#define OUTCOME_TRY_GLUE2(x, y) x##y +#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) +#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) +#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args +#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args +#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) +#if __has_cpp_attribute(likely) +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] +#endif +#endif +#ifndef OUTCOME_TRY_LIKELY_IF +#if defined(__clang__) || defined(__GNUC__) +#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1)) +#else +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) +#endif +#endif +#ifdef __cplusplus +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto +#else +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__) +#endif +#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE +#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED +#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) +#define OUTCOME_TRY2_VAR_SECOND2(x, var) var +#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y +#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic pop +#endif +#endif OUTCOME_V2_NAMESPACE_BEGIN namespace detail { @@ -6469,53 +6558,9 @@ OUTCOME_V2_NAMESPACE_END #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wparentheses" #endif -#define OUTCOME_TRY_GLUE2(x, y) x##y -#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) -#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) -#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args -#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args -#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) -#if __has_cpp_attribute(likely) -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] -#endif -#endif -#ifndef OUTCOME_TRY_LIKELY_IF -#if defined(__clang__) || defined(__GNUC__) -#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), true)) -#else -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) -#endif -#endif -#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) auto unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE -#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED -#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) // Use if(!expr); else as some compilers assume else clauses are always unlikely #define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } #define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } -#define OUTCOME_TRY2_VAR_SECOND2(x, var) var -#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y -#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) #define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) #define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) /*! AWAITING HUGO JSON CONVERSION TOOL diff --git a/single-header/outcome-experimental.hpp b/single-header/outcome-experimental.hpp index 689b63b698..94aa378a78 100644 --- a/single-header/outcome-experimental.hpp +++ b/single-header/outcome-experimental.hpp @@ -1044,9 +1044,9 @@ Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt) */ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define OUTCOME_PREVIOUS_COMMIT_REF 5bcd0f32f28659a0eab62f1d643d878c2220788d -#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-15 17:46:44 +00:00" -#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 5bcd0f32 +#define OUTCOME_PREVIOUS_COMMIT_REF b01ac71096775daf18d9a57a69be5e129f421a67 +#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 20:54:50 +00:00" +#define OUTCOME_PREVIOUS_COMMIT_UNIQUE b01ac710 #define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)) #ifdef _DEBUG #define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d))) @@ -3952,6 +3952,10 @@ Distributed under the Boost Software License, Version 1.0. #define OUTCOME_INLINE_GDB_PRETTY_PRINTER_H #ifndef OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS #if defined(__ELF__) +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Woverlength-strings" +#endif __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n" ".byte 4 /* Python Text */\n" ".ascii \"gdb.inlined-script\\n\"\n" @@ -4053,6 +4057,9 @@ __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n" ".ascii \"register_printers(gdb.current_objfile())\\n\"\n" ".byte 0\n" ".popsection\n"); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif #endif #endif #endif @@ -11645,6 +11652,88 @@ Distributed under the Boost Software License, Version 1.0. */ #ifndef OUTCOME_TRY_HPP #define OUTCOME_TRY_HPP +/* Try operation macros +(C) 2017-2024 Niall Douglas (20 commits) +File Created: July 2017 + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License in the accompanying file +Licence.txt or at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Distributed under the Boost Software License, Version 1.0. + (See accompanying file Licence.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef OUTCOME_TRY_H +#define OUTCOME_TRY_H +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wparentheses" +#endif +#define OUTCOME_TRY_GLUE2(x, y) x##y +#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) +#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) +#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args +#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args +#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) +#if __has_cpp_attribute(likely) +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] +#endif +#endif +#ifndef OUTCOME_TRY_LIKELY_IF +#if defined(__clang__) || defined(__GNUC__) +#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1)) +#else +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) +#endif +#endif +#ifdef __cplusplus +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto +#else +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__) +#endif +#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE +#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED +#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) +#define OUTCOME_TRY2_VAR_SECOND2(x, var) var +#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y +#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic pop +#endif +#endif OUTCOME_V2_NAMESPACE_BEGIN namespace detail { @@ -11780,53 +11869,9 @@ OUTCOME_V2_NAMESPACE_END #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wparentheses" #endif -#define OUTCOME_TRY_GLUE2(x, y) x##y -#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) -#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) -#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args -#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args -#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) -#if __has_cpp_attribute(likely) -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] -#endif -#endif -#ifndef OUTCOME_TRY_LIKELY_IF -#if defined(__clang__) || defined(__GNUC__) -#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), true)) -#else -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) -#endif -#endif -#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) auto unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE -#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED -#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) // Use if(!expr); else as some compilers assume else clauses are always unlikely #define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } #define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } -#define OUTCOME_TRY2_VAR_SECOND2(x, var) var -#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y -#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) #define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) #define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) /*! AWAITING HUGO JSON CONVERSION TOOL diff --git a/single-header/outcome.hpp b/single-header/outcome.hpp index 8caece5e9a..6882570c68 100644 --- a/single-header/outcome.hpp +++ b/single-header/outcome.hpp @@ -1043,9 +1043,9 @@ Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt) */ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define OUTCOME_PREVIOUS_COMMIT_REF 5bcd0f32f28659a0eab62f1d643d878c2220788d -#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-15 17:46:44 +00:00" -#define OUTCOME_PREVIOUS_COMMIT_UNIQUE 5bcd0f32 +#define OUTCOME_PREVIOUS_COMMIT_REF b01ac71096775daf18d9a57a69be5e129f421a67 +#define OUTCOME_PREVIOUS_COMMIT_DATE "2024-07-17 20:54:50 +00:00" +#define OUTCOME_PREVIOUS_COMMIT_UNIQUE b01ac710 #define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)) #ifdef _DEBUG #define OUTCOME_V2_CXX_MODULE_NAME QUICKCPPLIB_BIND_NAMESPACE((QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2d))) @@ -4864,6 +4864,10 @@ Distributed under the Boost Software License, Version 1.0. #define OUTCOME_INLINE_GDB_PRETTY_PRINTER_H #ifndef OUTCOME_DISABLE_INLINE_GDB_PRETTY_PRINTERS #if defined(__ELF__) +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Woverlength-strings" +#endif __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n" ".byte 4 /* Python Text */\n" ".ascii \"gdb.inlined-script\\n\"\n" @@ -4965,6 +4969,9 @@ __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n" ".ascii \"register_printers(gdb.current_objfile())\\n\"\n" ".byte 0\n" ".popsection\n"); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif #endif #endif #endif @@ -8297,6 +8304,88 @@ Distributed under the Boost Software License, Version 1.0. */ #ifndef OUTCOME_TRY_HPP #define OUTCOME_TRY_HPP +/* Try operation macros +(C) 2017-2024 Niall Douglas (20 commits) +File Created: July 2017 + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License in the accompanying file +Licence.txt or at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Distributed under the Boost Software License, Version 1.0. + (See accompanying file Licence.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +#ifndef OUTCOME_TRY_H +#define OUTCOME_TRY_H +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wparentheses" +#endif +#define OUTCOME_TRY_GLUE2(x, y) x##y +#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) +#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) +#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args +#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count +#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args +#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count +#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) +#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) +#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y +#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) +#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) +#if __has_cpp_attribute(likely) +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] +#endif +#endif +#ifndef OUTCOME_TRY_LIKELY_IF +#if defined(__clang__) || defined(__GNUC__) +#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), 1)) +#else +#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) +#endif +#endif +#ifdef __cplusplus +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) auto +#else +#define OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(...) __typeof__(__VA_ARGS__) +#endif +#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_AUTO(__VA_ARGS__) unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x +#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) +#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE +#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED +#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) +#define OUTCOME_TRY2_VAR_SECOND2(x, var) var +#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y +#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic pop +#endif +#endif OUTCOME_V2_NAMESPACE_BEGIN namespace detail { @@ -8432,53 +8521,9 @@ OUTCOME_V2_NAMESPACE_END #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wparentheses" #endif -#define OUTCOME_TRY_GLUE2(x, y) x##y -#define OUTCOME_TRY_GLUE(x, y) OUTCOME_TRY_GLUE2(x, y) -#define OUTCOME_TRY_UNIQUE_NAME OUTCOME_TRY_GLUE(_outcome_try_unique_name_temporary, __COUNTER__) -#define OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define OUTCOME_TRY_EXPAND_ARGS(args) OUTCOME_TRY_RETURN_ARG_COUNT args -#define OUTCOME_TRY_COUNT_ARGS_MAX8(...) OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define OUTCOME_TRY_OVERLOAD_MACRO1(name, count) OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define OUTCOME_TRY_OVERLOAD_MACRO(name, count) OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define OUTCOME_TRY_CALL_OVERLOAD(name, ...) OUTCOME_TRY_OVERLOAD_GLUE(OUTCOME_TRY_OVERLOAD_MACRO(name, OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#define _OUTCOME_TRY_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define _OUTCOME_TRY_EXPAND_ARGS(args) _OUTCOME_TRY_RETURN_ARG_COUNT args -#define _OUTCOME_TRY_COUNT_ARGS_MAX8(...) _OUTCOME_TRY_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) name##count -#define _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) _OUTCOME_TRY_OVERLOAD_MACRO2(name, count) -#define _OUTCOME_TRY_OVERLOAD_MACRO(name, count) _OUTCOME_TRY_OVERLOAD_MACRO1(name, count) -#define _OUTCOME_TRY_OVERLOAD_GLUE(x, y) x y -#define _OUTCOME_TRY_CALL_OVERLOAD(name, ...) _OUTCOME_TRY_OVERLOAD_GLUE(_OUTCOME_TRY_OVERLOAD_MACRO(name, _OUTCOME_TRY_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) -#if !defined(OUTCOME_TRY_LIKELY_IF) && defined(__has_cpp_attribute) -#if __has_cpp_attribute(likely) -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]] -#endif -#endif -#ifndef OUTCOME_TRY_LIKELY_IF -#if defined(__clang__) || defined(__GNUC__) -#define OUTCOME_TRY_LIKELY_IF(...) if(__builtin_expect(!!(__VA_ARGS__), true)) -#else -#define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) -#endif -#endif -#define OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK(...) __VA_ARGS__ -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, ...) auto unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE(unique, x, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE2(OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, x, y, ...) x unique = (__VA_ARGS__) -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(x) x -#define OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED(unique, ...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED2(OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED3(unique, __VA_ARGS__)) -#define OUTCOME_TRYV2_UNIQUE_STORAGE1(...) OUTCOME_TRYV2_UNIQUE_STORAGE_DEDUCE -#define OUTCOME_TRYV2_UNIQUE_STORAGE2(...) OUTCOME_TRYV2_UNIQUE_STORAGE_SPECIFIED -#define OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, ...) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRYV2_UNIQUE_STORAGE, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec) (unique, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, __VA_ARGS__) // Use if(!expr); else as some compilers assume else clauses are always unlikely #define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } #define OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(!OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)) { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast(unique))); retstmt unique##_f; } -#define OUTCOME_TRY2_VAR_SECOND2(x, var) var -#define OUTCOME_TRY2_VAR_SECOND3(x, y, ...) x y -#define OUTCOME_TRY2_VAR(spec) _OUTCOME_TRY_CALL_OVERLOAD(OUTCOME_TRY2_VAR_SECOND, OUTCOME_TRYV2_UNIQUE_STORAGE_UNPACK spec, spec) #define OUTCOME_TRY2_SUCCESS_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) #define OUTCOME_TRY2_FAILURE_LIKELY(unique, retstmt, var, ...) OUTCOME_TRYV3_FAILURE_LIKELY(unique, retstmt, var, __VA_ARGS__); OUTCOME_TRY2_VAR(var) = ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast(unique)) /*! AWAITING HUGO JSON CONVERSION TOOL