From 426dd8e08d73ec1eb1ee64a3c8db5cdd8627d3dd Mon Sep 17 00:00:00 2001 From: Filip Sajdak Date: Fri, 23 Aug 2024 22:52:44 +0200 Subject: [PATCH 1/3] Fix is_narrowing_v - closes #1257 The current implementation of `is_narrowing_v` does not handle type conversions correctly. For example, `cpp2::impl::is_narrowing_v` returns `false`, indicating that it mistakenly perceives the conversion from a signed `int` to an unsigned `size_t` as potentially non-narrowing. Closes #1257 --- include/cpp2util.h | 18 ++++-------------- source/reflect.h | 8 ++++---- source/reflect.h2 | 8 ++++---- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/include/cpp2util.h b/include/cpp2util.h index 51d28639f..568f3d71f 100644 --- a/include/cpp2util.h +++ b/include/cpp2util.h @@ -741,6 +741,9 @@ concept valid_custom_is_operator = predicate_member_fun || brace_initializable_to> ); +template +concept arithmetic = std::is_arithmetic_v>; + //----------------------------------------------------------------------- // // General helpers @@ -1759,20 +1762,7 @@ inline constexpr auto is( X const& x, bool (*value)(X const&) ) -> bool { // If it's confusing, we can switch this to template< typename To, typename From > -inline constexpr auto is_narrowing_v = - // [dcl.init.list] 7.1 - (std::is_floating_point_v && std::is_integral_v) || - // [dcl.init.list] 7.2 - (std::is_floating_point_v && std::is_floating_point_v && sizeof(From) > sizeof(To)) || - // [dcl.init.list] 7.3 - (std::is_integral_v && std::is_floating_point_v) || - (std::is_enum_v && std::is_floating_point_v) || - // [dcl.init.list] 7.4 - (std::is_integral_v && std::is_integral_v && sizeof(From) > sizeof(To)) || - (std::is_enum_v && std::is_integral_v && sizeof(From) > sizeof(To)) || - // [dcl.init.list] 7.5 - (std::is_pointer_v && std::is_same_v) - ; +concept is_narrowing_v = arithmetic && arithmetic && !brace_initializable_to; template< typename To, typename From > inline constexpr auto is_unsafe_pointer_conversion_v = diff --git a/source/reflect.h b/source/reflect.h index bce6e9f60..5f857fad7 100644 --- a/source/reflect.h +++ b/source/reflect.h @@ -3661,9 +3661,9 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} #line 1993 "reflect.h2" [[nodiscard]] auto parse_context::grab_n(cpp2::impl::in n, cpp2::impl::out r) & -> bool { - if (cpp2::impl::cmp_less_eq(pos + cpp2::impl::as_(n),regex.size())) { - r.construct(regex.substr(pos, cpp2::impl::as_(n))); - pos += (cpp2::impl::as_(n)) - 1; + if (cpp2::impl::cmp_less_eq(pos + cpp2::unsafe_narrow(n),regex.size())) { + r.construct(regex.substr(pos, cpp2::unsafe_narrow(n))); + pos += (cpp2::unsafe_narrow(n)) - 1; return true; } else { @@ -3844,7 +3844,7 @@ parse_context_branch_reset_state::parse_context_branch_reset_state(){} #line 2178 "reflect.h2" auto generation_function_context::remove_tabs(cpp2::impl::in c) & -> void{ - tabs = tabs.substr(0, (cpp2::impl::as_(c)) * 2); + tabs = tabs.substr(0, (cpp2::unsafe_narrow(c)) * 2); } generation_function_context::generation_function_context(auto const& code_, auto const& tabs_) diff --git a/source/reflect.h2 b/source/reflect.h2 index e9830f4f8..787e456eb 100644 --- a/source/reflect.h2 +++ b/source/reflect.h2 @@ -1992,9 +1992,9 @@ parse_context: type = grab_n: (inout this, in n: int, out r: std::string) -> bool = { - if pos + n as size_t <= regex..size() { - r = regex..substr(pos, n as size_t); - pos += (n as size_t) - 1; + if pos + unsafe_narrow(n) <= regex..size() { + r = regex..substr(pos, unsafe_narrow(n)); + pos += (unsafe_narrow(n)) - 1; return true; } else { @@ -2176,7 +2176,7 @@ generation_function_context: @struct type = { } remove_tabs: (inout this, c: int) = { - tabs = tabs..substr(0, (c as size_t) * 2); + tabs = tabs..substr(0, (unsafe_narrow(c)) * 2); } } From 537bf0dc1d62ac1230ecdff2019baa10107600f8 Mon Sep 17 00:00:00 2001 From: Filip Sajdak Date: Wed, 28 Aug 2024 00:48:40 +0200 Subject: [PATCH 2/3] Fix tests --- .../mixed-bounds-check.cpp.execution | 2 +- ...ed-bounds-safety-with-assert.cpp.execution | 2 +- ...-safety-3-contract-violation.cpp.execution | 2 +- ...me-safety-and-null-contracts.cpp.execution | 2 +- ...re2-assert-expected-not-null.cpp.execution | 2 +- ...re2-assert-optional-not-null.cpp.execution | 2 +- ...2-assert-shared-ptr-not-null.cpp.execution | 2 +- ...2-assert-unique-ptr-not-null.cpp.execution | 2 +- .../pure2-default-arguments.cpp.execution | 4 +- .../mixed-bounds-check.cpp.execution | 2 +- ...ed-bounds-safety-with-assert.cpp.execution | 2 +- ...-safety-3-contract-violation.cpp.execution | 2 +- ...me-safety-and-null-contracts.cpp.execution | 2 +- ...re2-assert-optional-not-null.cpp.execution | 2 +- ...2-assert-shared-ptr-not-null.cpp.execution | 2 +- ...2-assert-unique-ptr-not-null.cpp.execution | 2 +- .../pure2-default-arguments.cpp.execution | 4 +- .../pure2-default-arguments.cpp.output | 52 +++++++++---------- ...mixed-bugfix-for-ufcs-non-local.cpp.output | 20 +++---- .../pure2-default-arguments.cpp.execution | 4 +- ...mixed-bugfix-for-ufcs-non-local.cpp.output | 20 +++---- .../pure2-default-arguments.cpp.execution | 2 +- .../pure2-assert-expected-not-null.cpp.output | 4 +- .../pure2-default-arguments.cpp.execution | 4 +- 24 files changed, 76 insertions(+), 68 deletions(-) diff --git a/regression-tests/test-results/apple-clang-15-c++2b/mixed-bounds-check.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/mixed-bounds-check.cpp.execution index 60dbded0b..41b516b2d 100644 --- a/regression-tests/test-results/apple-clang-15-c++2b/mixed-bounds-check.cpp.execution +++ b/regression-tests/test-results/apple-clang-15-c++2b/mixed-bounds-check.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(1007) decltype(auto) cpp2::impl::assert_in_bounds(auto &&, std::source_location) [arg = 5, x:auto = std::vector]: Bounds safety violation: out of bounds access attempt detected - attempted access at index 5, [min,max] range is [0,4] +../../../include/cpp2util.h(1010) decltype(auto) cpp2::impl::assert_in_bounds(auto &&, std::source_location) [arg = 5, x:auto = std::vector]: Bounds safety violation: out of bounds access attempt detected - attempted access at index 5, [min,max] range is [0,4] diff --git a/regression-tests/test-results/apple-clang-15-c++2b/mixed-bounds-safety-with-assert.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/mixed-bounds-safety-with-assert.cpp.execution index 6effcd576..dd1028180 100644 --- a/regression-tests/test-results/apple-clang-15-c++2b/mixed-bounds-safety-with-assert.cpp.execution +++ b/regression-tests/test-results/apple-clang-15-c++2b/mixed-bounds-safety-with-assert.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(819) : Bounds safety violation +../../../include/cpp2util.h(822) : Bounds safety violation diff --git a/regression-tests/test-results/apple-clang-15-c++2b/mixed-initialization-safety-3-contract-violation.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/mixed-initialization-safety-3-contract-violation.cpp.execution index cda862f7c..dc6500b15 100644 --- a/regression-tests/test-results/apple-clang-15-c++2b/mixed-initialization-safety-3-contract-violation.cpp.execution +++ b/regression-tests/test-results/apple-clang-15-c++2b/mixed-initialization-safety-3-contract-violation.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(819) : Contract violation: fill: value must contain at least count elements +../../../include/cpp2util.h(822) : Contract violation: fill: value must contain at least count elements diff --git a/regression-tests/test-results/apple-clang-15-c++2b/mixed-lifetime-safety-and-null-contracts.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/mixed-lifetime-safety-and-null-contracts.cpp.execution index 121149a60..0617ee1ab 100644 --- a/regression-tests/test-results/apple-clang-15-c++2b/mixed-lifetime-safety-and-null-contracts.cpp.execution +++ b/regression-tests/test-results/apple-clang-15-c++2b/mixed-lifetime-safety-and-null-contracts.cpp.execution @@ -1,2 +1,2 @@ sending error to my framework... [dynamic null dereference attempt detected] -from source location: ../../../include/cpp2util.h(898) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&] +from source location: ../../../include/cpp2util.h(901) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&] diff --git a/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-expected-not-null.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-expected-not-null.cpp.execution index 3f3a6e9f4..29a1ab5e6 100644 --- a/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-expected-not-null.cpp.execution +++ b/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-expected-not-null.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(898) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::expected]: Null safety violation: std::expected has an unexpected value +../../../include/cpp2util.h(901) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::expected]: Null safety violation: std::expected has an unexpected value diff --git a/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-optional-not-null.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-optional-not-null.cpp.execution index 9529414a0..01d8c59b8 100644 --- a/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-optional-not-null.cpp.execution +++ b/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-optional-not-null.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(898) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::optional]: Null safety violation: std::optional does not contain a value +../../../include/cpp2util.h(901) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::optional]: Null safety violation: std::optional does not contain a value diff --git a/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-shared-ptr-not-null.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-shared-ptr-not-null.cpp.execution index 3eba52e06..6c2014bab 100644 --- a/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-shared-ptr-not-null.cpp.execution +++ b/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-shared-ptr-not-null.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(898) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::shared_ptr]: Null safety violation: std::shared_ptr is empty +../../../include/cpp2util.h(901) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::shared_ptr]: Null safety violation: std::shared_ptr is empty diff --git a/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-unique-ptr-not-null.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-unique-ptr-not-null.cpp.execution index a56bf4305..9610f5ae8 100644 --- a/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-unique-ptr-not-null.cpp.execution +++ b/regression-tests/test-results/apple-clang-15-c++2b/pure2-assert-unique-ptr-not-null.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(898) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::unique_ptr]: Null safety violation: std::unique_ptr is empty +../../../include/cpp2util.h(901) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::unique_ptr]: Null safety violation: std::unique_ptr is empty diff --git a/regression-tests/test-results/apple-clang-15-c++2b/pure2-default-arguments.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/pure2-default-arguments.cpp.execution index 71d4adcb8..a49873036 100644 --- a/regression-tests/test-results/apple-clang-15-c++2b/pure2-default-arguments.cpp.execution +++ b/regression-tests/test-results/apple-clang-15-c++2b/pure2-default-arguments.cpp.execution @@ -1,2 +1,4 @@ calling: -012an older compiler +012 +an older compiler +1, 1, 66 diff --git a/regression-tests/test-results/clang-15-c++20/mixed-bounds-check.cpp.execution b/regression-tests/test-results/clang-15-c++20/mixed-bounds-check.cpp.execution index 60dbded0b..41b516b2d 100644 --- a/regression-tests/test-results/clang-15-c++20/mixed-bounds-check.cpp.execution +++ b/regression-tests/test-results/clang-15-c++20/mixed-bounds-check.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(1007) decltype(auto) cpp2::impl::assert_in_bounds(auto &&, std::source_location) [arg = 5, x:auto = std::vector]: Bounds safety violation: out of bounds access attempt detected - attempted access at index 5, [min,max] range is [0,4] +../../../include/cpp2util.h(1010) decltype(auto) cpp2::impl::assert_in_bounds(auto &&, std::source_location) [arg = 5, x:auto = std::vector]: Bounds safety violation: out of bounds access attempt detected - attempted access at index 5, [min,max] range is [0,4] diff --git a/regression-tests/test-results/clang-15-c++20/mixed-bounds-safety-with-assert.cpp.execution b/regression-tests/test-results/clang-15-c++20/mixed-bounds-safety-with-assert.cpp.execution index 6effcd576..dd1028180 100644 --- a/regression-tests/test-results/clang-15-c++20/mixed-bounds-safety-with-assert.cpp.execution +++ b/regression-tests/test-results/clang-15-c++20/mixed-bounds-safety-with-assert.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(819) : Bounds safety violation +../../../include/cpp2util.h(822) : Bounds safety violation diff --git a/regression-tests/test-results/clang-15-c++20/mixed-initialization-safety-3-contract-violation.cpp.execution b/regression-tests/test-results/clang-15-c++20/mixed-initialization-safety-3-contract-violation.cpp.execution index cda862f7c..dc6500b15 100644 --- a/regression-tests/test-results/clang-15-c++20/mixed-initialization-safety-3-contract-violation.cpp.execution +++ b/regression-tests/test-results/clang-15-c++20/mixed-initialization-safety-3-contract-violation.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(819) : Contract violation: fill: value must contain at least count elements +../../../include/cpp2util.h(822) : Contract violation: fill: value must contain at least count elements diff --git a/regression-tests/test-results/clang-15-c++20/mixed-lifetime-safety-and-null-contracts.cpp.execution b/regression-tests/test-results/clang-15-c++20/mixed-lifetime-safety-and-null-contracts.cpp.execution index 121149a60..0617ee1ab 100644 --- a/regression-tests/test-results/clang-15-c++20/mixed-lifetime-safety-and-null-contracts.cpp.execution +++ b/regression-tests/test-results/clang-15-c++20/mixed-lifetime-safety-and-null-contracts.cpp.execution @@ -1,2 +1,2 @@ sending error to my framework... [dynamic null dereference attempt detected] -from source location: ../../../include/cpp2util.h(898) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&] +from source location: ../../../include/cpp2util.h(901) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&] diff --git a/regression-tests/test-results/clang-15-c++20/pure2-assert-optional-not-null.cpp.execution b/regression-tests/test-results/clang-15-c++20/pure2-assert-optional-not-null.cpp.execution index 9529414a0..01d8c59b8 100644 --- a/regression-tests/test-results/clang-15-c++20/pure2-assert-optional-not-null.cpp.execution +++ b/regression-tests/test-results/clang-15-c++20/pure2-assert-optional-not-null.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(898) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::optional]: Null safety violation: std::optional does not contain a value +../../../include/cpp2util.h(901) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::optional]: Null safety violation: std::optional does not contain a value diff --git a/regression-tests/test-results/clang-15-c++20/pure2-assert-shared-ptr-not-null.cpp.execution b/regression-tests/test-results/clang-15-c++20/pure2-assert-shared-ptr-not-null.cpp.execution index 3eba52e06..6c2014bab 100644 --- a/regression-tests/test-results/clang-15-c++20/pure2-assert-shared-ptr-not-null.cpp.execution +++ b/regression-tests/test-results/clang-15-c++20/pure2-assert-shared-ptr-not-null.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(898) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::shared_ptr]: Null safety violation: std::shared_ptr is empty +../../../include/cpp2util.h(901) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::shared_ptr]: Null safety violation: std::shared_ptr is empty diff --git a/regression-tests/test-results/clang-15-c++20/pure2-assert-unique-ptr-not-null.cpp.execution b/regression-tests/test-results/clang-15-c++20/pure2-assert-unique-ptr-not-null.cpp.execution index a56bf4305..9610f5ae8 100644 --- a/regression-tests/test-results/clang-15-c++20/pure2-assert-unique-ptr-not-null.cpp.execution +++ b/regression-tests/test-results/clang-15-c++20/pure2-assert-unique-ptr-not-null.cpp.execution @@ -1 +1 @@ -../../../include/cpp2util.h(898) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::unique_ptr]: Null safety violation: std::unique_ptr is empty +../../../include/cpp2util.h(901) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::unique_ptr]: Null safety violation: std::unique_ptr is empty diff --git a/regression-tests/test-results/clang-15-c++20/pure2-default-arguments.cpp.execution b/regression-tests/test-results/clang-15-c++20/pure2-default-arguments.cpp.execution index 71d4adcb8..a49873036 100644 --- a/regression-tests/test-results/clang-15-c++20/pure2-default-arguments.cpp.execution +++ b/regression-tests/test-results/clang-15-c++20/pure2-default-arguments.cpp.execution @@ -1,2 +1,4 @@ calling: -012an older compiler +012 +an older compiler +1, 1, 66 diff --git a/regression-tests/test-results/gcc-10-c++20/pure2-default-arguments.cpp.output b/regression-tests/test-results/gcc-10-c++20/pure2-default-arguments.cpp.output index 471a03f02..ca42652e9 100644 --- a/regression-tests/test-results/gcc-10-c++20/pure2-default-arguments.cpp.output +++ b/regression-tests/test-results/gcc-10-c++20/pure2-default-arguments.cpp.output @@ -1,66 +1,66 @@ In file included from pure2-default-arguments.cpp:7: ../../../include/cpp2util.h:2086:28: error: local variable ‘obj’ may not appear in this context - 2086 | auto as( std::variant & x ) -> decltype(auto) { + 2086 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 9>(x)), T >) { if (x.index() == 9) return operator_as<9>(x); } | ^~~ ../../../include/cpp2util.h:2047:34: note: in definition of macro ‘CPP2_UFCS_IDENTITY’ - 2047 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<15>(x)), T >) { if (x.index() == 15) return true; } - | ^~~~~~~~~~~ + 2047 | return false; + | ^ ../../../include/cpp2util.h:2086:15: note: in expansion of macro ‘CPP2_FORWARD’ - 2086 | auto as( std::variant & x ) -> decltype(auto) { + 2086 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 9>(x)), T >) { if (x.index() == 9) return operator_as<9>(x); } | ^~~~~~~~~~~~ ../../../include/cpp2util.h:2107:22: note: in expansion of macro ‘CPP2_UFCS_CONSTRAINT_ARG’ - 2107 | Throw( std::bad_variant_access(), "'as' cast failed for 'variant'"); + 2107 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 5>(x)), T >) { if (x.index() == 5) return operator_as<5>(x); } | ^~~~~~~~~~~~~~~~~~~~~~~~ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ pure2-default-arguments.cpp2:6:22: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ ../../../include/cpp2util.h:2086:92: error: local variable ‘params’ may not appear in this context - 2086 | auto as( std::variant & x ) -> decltype(auto) { - | ^ + 2086 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 9>(x)), T >) { if (x.index() == 9) return operator_as<9>(x); } + | ^~~~~~ ../../../include/cpp2util.h:2047:34: note: in definition of macro ‘CPP2_UFCS_IDENTITY’ - 2047 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<15>(x)), T >) { if (x.index() == 15) return true; } - | ^~~~~~~~~~~ + 2047 | return false; + | ^ ../../../include/cpp2util.h:2086:79: note: in expansion of macro ‘CPP2_FORWARD’ - 2086 | auto as( std::variant & x ) -> decltype(auto) { - | ^ + 2086 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 9>(x)), T >) { if (x.index() == 9) return operator_as<9>(x); } + | ^~~~~~~~~~~~ ../../../include/cpp2util.h:2107:22: note: in expansion of macro ‘CPP2_UFCS_CONSTRAINT_ARG’ - 2107 | Throw( std::bad_variant_access(), "'as' cast failed for 'variant'"); + 2107 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 5>(x)), T >) { if (x.index() == 5) return operator_as<5>(x); } | ^~~~~~~~~~~~~~~~~~~~~~~~ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ pure2-default-arguments.cpp2:6:22: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ ../../../include/cpp2util.h:2087:74: error: local variable ‘obj’ may not appear in this context - 2087 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 0>(x)), T >) { if (x.index() == 0) return operator_as<0>(x); } + 2087 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<10>(x)), T >) { if (x.index() == 10) return operator_as<10>(x); } | ^~~ ../../../include/cpp2util.h:2047:34: note: in definition of macro ‘CPP2_UFCS_IDENTITY’ - 2047 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<15>(x)), T >) { if (x.index() == 15) return true; } - | ^~~~~~~~~~~ + 2047 | return false; + | ^ ../../../include/cpp2util.h:2087:61: note: in expansion of macro ‘CPP2_FORWARD’ - 2087 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 0>(x)), T >) { if (x.index() == 0) return operator_as<0>(x); } + 2087 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<10>(x)), T >) { if (x.index() == 10) return operator_as<10>(x); } | ^~~~~~~~~~~~ ../../../include/cpp2util.h:2107:22: note: in expansion of macro ‘CPP2_UFCS_CONSTRAINT_ARG’ - 2107 | Throw( std::bad_variant_access(), "'as' cast failed for 'variant'"); + 2107 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 5>(x)), T >) { if (x.index() == 5) return operator_as<5>(x); } | ^~~~~~~~~~~~~~~~~~~~~~~~ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ pure2-default-arguments.cpp2:6:22: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ ../../../include/cpp2util.h:2087:93: error: local variable ‘params’ may not appear in this context - 2087 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 0>(x)), T >) { if (x.index() == 0) return operator_as<0>(x); } + 2087 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<10>(x)), T >) { if (x.index() == 10) return operator_as<10>(x); } | ^~~~~~ ../../../include/cpp2util.h:2047:34: note: in definition of macro ‘CPP2_UFCS_IDENTITY’ - 2047 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<15>(x)), T >) { if (x.index() == 15) return true; } - | ^~~~~~~~~~~ + 2047 | return false; + | ^ ../../../include/cpp2util.h:2087:80: note: in expansion of macro ‘CPP2_FORWARD’ - 2087 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 0>(x)), T >) { if (x.index() == 0) return operator_as<0>(x); } + 2087 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<10>(x)), T >) { if (x.index() == 10) return operator_as<10>(x); } | ^~~~~~~~~~~~ ../../../include/cpp2util.h:2107:22: note: in expansion of macro ‘CPP2_UFCS_CONSTRAINT_ARG’ - 2107 | Throw( std::bad_variant_access(), "'as' cast failed for 'variant'"); + 2107 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as< 5>(x)), T >) { if (x.index() == 5) return operator_as<5>(x); } | ^~~~~~~~~~~~~~~~~~~~~~~~ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ pure2-default-arguments.cpp2:6:22: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ pure2-default-arguments.cpp2:6:61: error: ‘std::source_location’ has not been declared diff --git a/regression-tests/test-results/gcc-13-c++2b/mixed-bugfix-for-ufcs-non-local.cpp.output b/regression-tests/test-results/gcc-13-c++2b/mixed-bugfix-for-ufcs-non-local.cpp.output index 2bdfe9d16..2ce0c1abc 100644 --- a/regression-tests/test-results/gcc-13-c++2b/mixed-bugfix-for-ufcs-non-local.cpp.output +++ b/regression-tests/test-results/gcc-13-c++2b/mixed-bugfix-for-ufcs-non-local.cpp.output @@ -1,41 +1,41 @@ In file included from mixed-bugfix-for-ufcs-non-local.cpp:6: ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:13:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:13:36: error: template argument 1 is invalid ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:21:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:21:36: error: template argument 1 is invalid ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:31:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:31:36: error: template argument 1 is invalid ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:33:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:33:36: error: template argument 1 is invalid ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:21:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:21:36: error: template argument 1 is invalid diff --git a/regression-tests/test-results/gcc-13-c++2b/pure2-default-arguments.cpp.execution b/regression-tests/test-results/gcc-13-c++2b/pure2-default-arguments.cpp.execution index 13c1bc1e7..afb167feb 100644 --- a/regression-tests/test-results/gcc-13-c++2b/pure2-default-arguments.cpp.execution +++ b/regression-tests/test-results/gcc-13-c++2b/pure2-default-arguments.cpp.execution @@ -1,2 +1,4 @@ calling: int main(int, char**) -012an older compiler +012 +an older compiler +1, 1, 66 diff --git a/regression-tests/test-results/gcc-14-c++2b/mixed-bugfix-for-ufcs-non-local.cpp.output b/regression-tests/test-results/gcc-14-c++2b/mixed-bugfix-for-ufcs-non-local.cpp.output index 2bdfe9d16..2ce0c1abc 100644 --- a/regression-tests/test-results/gcc-14-c++2b/mixed-bugfix-for-ufcs-non-local.cpp.output +++ b/regression-tests/test-results/gcc-14-c++2b/mixed-bugfix-for-ufcs-non-local.cpp.output @@ -1,41 +1,41 @@ In file included from mixed-bugfix-for-ufcs-non-local.cpp:6: ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:13:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:13:36: error: template argument 1 is invalid ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:21:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:21:36: error: template argument 1 is invalid ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:31:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:31:36: error: template argument 1 is invalid ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:33:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:33:36: error: template argument 1 is invalid ../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type - 2100 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<13>(x)), T >) { if (x.index() == 13) return operator_as<13>(x); } + 2100 | template | ^ ../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’ - 2137 | // std::any is and as + 2137 | template | ^ mixed-bugfix-for-ufcs-non-local.cpp2:21:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’ mixed-bugfix-for-ufcs-non-local.cpp2:21:36: error: template argument 1 is invalid diff --git a/regression-tests/test-results/gcc-14-c++2b/pure2-default-arguments.cpp.execution b/regression-tests/test-results/gcc-14-c++2b/pure2-default-arguments.cpp.execution index 0d1459552..afb167feb 100644 --- a/regression-tests/test-results/gcc-14-c++2b/pure2-default-arguments.cpp.execution +++ b/regression-tests/test-results/gcc-14-c++2b/pure2-default-arguments.cpp.execution @@ -1,4 +1,4 @@ calling: int main(int, char**) 012 -a newer compiler +an older compiler 1, 1, 66 diff --git a/regression-tests/test-results/msvc-2022-c++20/pure2-assert-expected-not-null.cpp.output b/regression-tests/test-results/msvc-2022-c++20/pure2-assert-expected-not-null.cpp.output index e069d85fd..35af3e64f 100644 --- a/regression-tests/test-results/msvc-2022-c++20/pure2-assert-expected-not-null.cpp.output +++ b/regression-tests/test-results/msvc-2022-c++20/pure2-assert-expected-not-null.cpp.output @@ -6,7 +6,7 @@ pure2-assert-expected-not-null.cpp2(7): error C2143: syntax error: missing ';' b pure2-assert-expected-not-null.cpp2(7): error C2143: syntax error: missing ';' before '}' pure2-assert-expected-not-null.cpp2(9): error C2065: 'ex': undeclared identifier pure2-assert-expected-not-null.cpp2(9): error C2672: 'cpp2::impl::assert_not_null': no matching overloaded function found -..\..\..\include\cpp2util.h(898): note: could be 'decltype(auto) cpp2::impl::assert_not_null(_T0 &&,std::source_location)' +..\..\..\include\cpp2util.h(901): note: could be 'decltype(auto) cpp2::impl::assert_not_null(_T0 &&,std::source_location)' pure2-assert-expected-not-null.cpp2(14): error C2039: 'expected': is not a member of 'std' predefined C++ types (compiler internal)(347): note: see declaration of 'std' pure2-assert-expected-not-null.cpp2(14): error C2062: type 'int' unexpected @@ -19,4 +19,4 @@ pure2-assert-expected-not-null.cpp2(14): note: while trying to match the argumen pure2-assert-expected-not-null.cpp2(14): error C2143: syntax error: missing ';' before '}' pure2-assert-expected-not-null.cpp2(15): error C2065: 'ex': undeclared identifier pure2-assert-expected-not-null.cpp2(15): error C2672: 'cpp2::impl::assert_not_null': no matching overloaded function found -..\..\..\include\cpp2util.h(898): note: could be 'decltype(auto) cpp2::impl::assert_not_null(_T0 &&,std::source_location)' +..\..\..\include\cpp2util.h(901): note: could be 'decltype(auto) cpp2::impl::assert_not_null(_T0 &&,std::source_location)' diff --git a/regression-tests/test-results/msvc-2022-c++20/pure2-default-arguments.cpp.execution b/regression-tests/test-results/msvc-2022-c++20/pure2-default-arguments.cpp.execution index 75f26d0fc..28b9d2515 100644 --- a/regression-tests/test-results/msvc-2022-c++20/pure2-default-arguments.cpp.execution +++ b/regression-tests/test-results/msvc-2022-c++20/pure2-default-arguments.cpp.execution @@ -1,2 +1,4 @@ calling: int __cdecl main(const int,char **) -012a newer compiler +012 +a newer compiler +1, 1, 66 From e60e0b0544869a56e8fa19933b9c2816f9485193 Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Mon, 23 Sep 2024 18:17:38 -1000 Subject: [PATCH 3/3] Re-run regression tests locally on my machine --- .../gcc-14-c++2b/pure2-default-arguments.cpp.execution | 2 +- .../gcc-14-c++2b/pure2-range-operators.cpp.execution | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/regression-tests/test-results/gcc-14-c++2b/pure2-default-arguments.cpp.execution b/regression-tests/test-results/gcc-14-c++2b/pure2-default-arguments.cpp.execution index afb167feb..0d1459552 100644 --- a/regression-tests/test-results/gcc-14-c++2b/pure2-default-arguments.cpp.execution +++ b/regression-tests/test-results/gcc-14-c++2b/pure2-default-arguments.cpp.execution @@ -1,4 +1,4 @@ calling: int main(int, char**) 012 -an older compiler +a newer compiler 1, 1, 66 diff --git a/regression-tests/test-results/gcc-14-c++2b/pure2-range-operators.cpp.execution b/regression-tests/test-results/gcc-14-c++2b/pure2-range-operators.cpp.execution index 9168b08ea..df04174c1 100644 --- a/regression-tests/test-results/gcc-14-c++2b/pure2-range-operators.cpp.execution +++ b/regression-tests/test-results/gcc-14-c++2b/pure2-range-operators.cpp.execution @@ -34,3 +34,6 @@ true true false false + +Make sure views::take works: +1 2 3 4 5 2 3 4 \ No newline at end of file