From e0bf3ece6ec91d4d73f05b65afe89d8f5b3fca06 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Fri, 26 Sep 2025 13:12:02 -0600 Subject: [PATCH] :rotating_light: Fix warnings arising from `-Wnrvo` Problem: - `stdx` is not warning free with respect to `-Wnrvo`. Solution: - Add some trailing return types etc to fix warnings. --- include/stdx/bit.hpp | 18 +++++++++++------- include/stdx/ct_format.hpp | 20 ++++++++++++-------- include/stdx/tuple.hpp | 18 ++++++++++-------- include/stdx/tuple_algorithms.hpp | 19 +++++++++++-------- 4 files changed, 44 insertions(+), 31 deletions(-) diff --git a/include/stdx/bit.hpp b/include/stdx/bit.hpp index 3706177..44e8d90 100644 --- a/include/stdx/bit.hpp +++ b/include/stdx/bit.hpp @@ -334,11 +334,13 @@ template constexpr auto bit_unpack(From arg) { "bit_unpack is undefined for those types"); constexpr auto sz = sized{1}.template in(); - auto r = bit_cast>(to_be(arg)); - for (auto &elem : r) { - elem = from_be(elem); - } - return r; + return [&]() -> std::array { + auto r = bit_cast>(to_be(arg)); + for (auto &elem : r) { + elem = from_be(elem); + } + return r; + }(); } namespace detail { @@ -436,14 +438,16 @@ template using smallest_uint_t = decltype(smallest_uint()); namespace bit_detail { template -constexpr auto shifts = [] { +constexpr auto shifts = + []() -> std::array { constexpr auto offsets = std::array{std::size_t{}, Offsets...}; auto s = std::array{}; for (auto i = std::size_t{}; i < sizeof...(Offsets); ++i) { s[i + 1] = offsets[i + 1] - offsets[i]; } return s; -}(); +} +(); template constexpr auto shift_extract(T &t) -> T { diff --git a/include/stdx/ct_format.hpp b/include/stdx/ct_format.hpp index 6fdd687..3427bdb 100644 --- a/include/stdx/ct_format.hpp +++ b/include/stdx/ct_format.hpp @@ -106,7 +106,9 @@ CONSTEVAL auto count_specifiers(std::string_view fmt) -> std::size_t { return count; } -template CONSTEVAL auto split_specifiers(std::string_view fmt) { +template +CONSTEVAL auto split_specifiers(std::string_view fmt) + -> std::array { auto splits = std::array{}; auto count = std::size_t{}; @@ -196,24 +198,26 @@ CONSTEVAL auto convert_output() { } } +template +CONSTEVAL auto perform_format(auto s, auto v) -> ct_string { + ct_string cts{}; + fmt::format_to(cts.begin(), s, v); + return cts; +} + template constexpr auto format1(Arg arg) { if constexpr (requires { arg_value(arg); }) { constexpr auto fmtstr = FMT_COMPILE(std::string_view{Fmt}); constexpr auto a = arg_value(arg); - auto const f = [](auto s, auto v) { - ct_string cts{}; - fmt::format_to(cts.begin(), s, v); - return cts; - }; if constexpr (is_specialization_of_v, format_result>) { constexpr auto s = convert_input(a.str); constexpr auto sz = fmt::formatted_size(fmtstr, s); - constexpr auto cts = f.template operator()(fmtstr, s); + constexpr auto cts = perform_format(fmtstr, s); return format_result{cts_t{}, a.args}; } else { constexpr auto sz = fmt::formatted_size(fmtstr, a); - constexpr auto cts = f.template operator()(fmtstr, a); + constexpr auto cts = perform_format(fmtstr, a); return format_result{cts_t{}}; } } else if constexpr (is_specialization_of_v) { diff --git a/include/stdx/tuple.hpp b/include/stdx/tuple.hpp index 9f2501a..b037e15 100644 --- a/include/stdx/tuple.hpp +++ b/include/stdx/tuple.hpp @@ -369,14 +369,16 @@ struct tuple_impl, index_function_list, Ts...> using C = std::common_comparison_category_t] <=> rhs[index])...>; - C result = lhs[index<0>] <=> rhs[index<0>]; - auto const compare_at = [&]() { - result = lhs[index] <=> rhs[index]; - return result != 0; - }; - [[maybe_unused]] auto b = - (compare_at.template operator()() or ...); - return result; + return [&]() -> C { + C result = lhs[index<0>] <=> rhs[index<0>]; + auto const compare_at = [&]() { + result = lhs[index] <=> rhs[index]; + return result != 0; + }; + [[maybe_unused]] auto b = + (compare_at.template operator()() or ...); + return result; + }(); } } }; diff --git a/include/stdx/tuple_algorithms.hpp b/include/stdx/tuple_algorithms.hpp index 5c302a6..2f4e452 100644 --- a/include/stdx/tuple_algorithms.hpp +++ b/include/stdx/tuple_algorithms.hpp @@ -20,7 +20,8 @@ template constexpr auto apply(F &&f, Ts &&...ts) { constexpr auto total_num_elements = (std::size_t{} + ... + stdx::tuple_size_v>); - [[maybe_unused]] constexpr auto element_indices = [&] { + [[maybe_unused]] constexpr auto element_indices = + [&]() -> std::array { std::array indices{}; [[maybe_unused]] auto p = indices.data(); ((p = std::remove_cvref_t::fill_inner_indices(p)), ...); @@ -48,7 +49,8 @@ template [[nodiscard]] constexpr auto tuple_cat(Ts &&...ts) { constexpr auto total_num_elements = (std::size_t{} + ... + stdx::tuple_size_v>); - [[maybe_unused]] constexpr auto element_indices = [&] { + [[maybe_unused]] constexpr auto element_indices = + [&]() -> std::array { std::array indices{}; auto p = indices.data(); ((p = std::remove_cvref_t::fill_inner_indices(p)), ...); @@ -112,7 +114,7 @@ template