Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASSERT that iterator is not .end() fails to compile in v2.0.0, VERIFY built with v1.2.2 #90

Closed
Hailios opened this issue Apr 2, 2024 · 3 comments

Comments

@Hailios
Copy link

Hailios commented Apr 2, 2024

hey, I've updated libassert to 2.0.0 with conan from 1.2.2. some assertions that previously built, now fails to do so.

this is the offending code that now fails sto compile.

auto host_it = req.find(boost::beast::http::field::host);
ASSERT(host_it != req.end());

req is of type boost::beast::http::request<boost::beast::http::string_body>& from https://github.com/boostorg/beast/ using boost 1.84.

user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp: In instantiation of 'constexpr const bool libassert::detail::stringifiable<boost::beast::http::basic_fields<std::allocator<char> >::value_type>':
user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp:576:20:   required from 'constexpr bool libassert::detail::stringifiable_container() [with T = boost::beast::http::basic_fields<std::allocator<char> >::element]'
user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp:557:83:   required from 'constexpr const bool libassert::detail::stringifiable<boost::beast::http::basic_fields<std::allocator<char> >::element>'
user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp:576:20:   required from 'constexpr bool libassert::detail::stringifiable_container() [with T = boost::intrusive::list_iterator<boost::intrusive::bhtraits<boost::beast::http::basic_fields<std::allocator<char> >::element, boost::intrusive::list_node_traits<void*>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 1>, true>]'
user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp:647:42:   required from 'std::string libassert::detail::generate_stringification(const T&) [with T = boost::intrusive::list_iterator<boost::intrusive::bhtraits<boost::beast::http::basic_fields<std::allocator<char> >::element, boost::intrusive::list_node_traits<void*>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 1>, true>; std::string = std::__cxx11::basic_string<char>]'
user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp:1261:37:   required from 'libassert::binary_diagnostics_descriptor libassert::detail::generate_binary_diagnostic(const A&, const B&, std::string_view, std::string_view, std::string_view) [with A = boost::intrusive::list_iterator<boost::intrusive::bhtraits<boost::beast::http::basic_fields<std::allocator<char> >::element, boost::intrusive::list_node_traits<void*>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 1>, true>; B = boost::intrusive::list_iterator<boost::intrusive::bhtraits<boost::beast::http::basic_fields<std::allocator<char> >::element, boost::intrusive::list_node_traits<void*>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 1>, true>; std::string_view = std::basic_string_view<char>]'
user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp:1363:65:   required from 'void libassert::detail::process_assert_fail(expression_decomposer<A, B, C>&, const assert_static_parameters*, Args&& ...) [with A = boost::intrusive::list_iterator<boost::intrusive::bhtraits<boost::beast::http::basic_fields<std::allocator<char> >::element, boost::intrusive::list_node_traits<void*>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 1>, true>&; B = boost::intrusive::list_iterator<boost::intrusive::bhtraits<boost::beast::http::basic_fields<std::allocator<char> >::element, boost::intrusive::list_node_traits<void*>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 1>, true>; C = ops::neq; Args = {pretty_function_name_wrapper}]'
user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp:1416:28:   required from 'void libassert::detail::process_assert_fail_n(expression_decomposer<A, B, C>, const assert_static_parameters*, Args&& ...) [with A = boost::intrusive::list_iterator<boost::intrusive::bhtraits<boost::beast::http::basic_fields<std::allocator<char> >::element, boost::intrusive::list_node_traits<void*>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 1>, true>&; B = boost::intrusive::list_iterator<boost::intrusive::bhtraits<boost::beast::http::basic_fields<std::allocator<char> >::element, boost::intrusive::list_node_traits<void*>, boost::intrusive::normal_link, boost::intrusive::dft_tag, 1>, true>; C = ops::neq; Args = {pretty_function_name_wrapper}]'
user/development/git/c++/HttpsSession.cpp:62:3:   required from here
user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp:560:38:   in 'constexpr' expansion of 'libassert::detail::stringifiable_container<boost::beast::http::basic_fields<std::allocator<char> >::value_type>()'
user/.conan2/p/b/libas3514cb9b8f850/p/include/libassert/assert.hpp:576:20: error: the value of 'libassert::detail::stringifiable<boost::beast::http::basic_fields<std::allocator<char> >::value_type>' is not usable in a constant expression
  576 |             return stringifiable<typename T::value_type>;
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

built using

$ g++ --version
g++ (Ubuntu 13.2.0-4ubuntu3) 13.2.0
@jeremy-rifkin
Copy link
Owner

Thank you for reporting this, I’ll try to fix it tonight

@jeremy-rifkin
Copy link
Owner

I can reproduce for gcc 13.2, however it compiles fine in clang https://godbolt.org/z/bjqbEoGWj

@jeremy-rifkin
Copy link
Owner

jeremy-rifkin commented Apr 3, 2024

I have found the problem.
note: 'libassert::detail::stringifiable<boost::beast::http::basic_fields<std::allocator<char> >::value_type>' used in its own initializer confused me a lot but the basic error boils down to

<source>: In instantiation of 'constexpr const bool stringifiable<boost::beast::http::basic_fields<std::allocator<char> >::value_type>':
<source>:60:16:   required from 'constexpr bool stringifiable_container() [with T = boost::beast::http::basic_fields<std::allocator<char> >::value_type]'
<source>:71:111:   required from here
<source>:44:34: error: 'constexpr bool stringifiable_container() [with T = boost::beast::http::basic_fields<std::allocator<char> >::value_type]' called in a constant expression before its definition is complete
   44 |     || stringifiable_container<T>();
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~^~

So... recursively checking T::value_type somehow leads back to T, which is a problem. It may be due to the basic_fields::value_type not being a using as is normal but a class named value_type instead. I'll have to try to better understand why this behaves as it does but for now it can be solved by checking std::is_same_v<typename T::value_type, T>. https://godbolt.org/z/vo6svn34W

Repro without boost: https://godbolt.org/z/1xf1hMdbd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants