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

Problems with BOOST_TYPE_ERASURE_MEMBER #345

Closed
jonesmz opened this issue Aug 22, 2019 · 17 comments
Closed

Problems with BOOST_TYPE_ERASURE_MEMBER #345

jonesmz opened this issue Aug 22, 2019 · 17 comments

Comments

@jonesmz
Copy link
Contributor

jonesmz commented Aug 22, 2019

I'm currently using Boost 1.65 (It's what my operating system comes with).

I just pulled the newly merged code for #320 and am now seeing this error.

mqtt_cpp/include/mqtt/type_erased_socket.hpp:23: error: macro "BOOST_PP_SEQ_ELEM_III" requires 2 arguments, but only 1 given
BOOST_TYPE_ERASURE_MEMBER(has_async_read, async_read)
^~~~~~~~~~~~~~~~~~~

What version of boost do you consider the minimum required version?

@redboltz
Copy link
Owner

It seems that 1.67.0 or later is required.

But if you replace them, older boost version could be used.

// place them out of mqtt namespace (global namespace)
// BOOST_TYPE_ERASURE_MEMBER((name_space)(has_func_name), func_name, num_of_params)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_async_read), async_read, 3)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_async_write), async_write, 3)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_write), write, 2)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_post), post, 1)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_lowest_layer), lowest_layer, 0)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_close), close, 1)

I should update README.md.

@redboltz
Copy link
Owner

Could you replace and test the following file?

type_erased_socket.hpp

// Copyright Takatoshi Kondo 2019
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#if !defined(MQTT_TYPE_ERASED_SOCKET_HPP)
#define MQTT_TYPE_ERASED_SOCKET_HPP

#include <cstdlib>

#include <boost/config/workaround.hpp>
#include <boost/type_erasure/member.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio.hpp>

#include <mqtt/shared_any.hpp>

#if BOOST_VERSION >= 106700

namespace mqtt {

// New style boost type_erasure member fucntion concept definition
BOOST_TYPE_ERASURE_MEMBER(has_async_read, async_read)
BOOST_TYPE_ERASURE_MEMBER(has_async_write, async_write)
BOOST_TYPE_ERASURE_MEMBER(has_write, write)
BOOST_TYPE_ERASURE_MEMBER(has_post, post)
BOOST_TYPE_ERASURE_MEMBER(has_lowest_layer, lowest_layer)
BOOST_TYPE_ERASURE_MEMBER(has_close, close)

} // namespace mqtt

#else //  BOOST_VERSION >= 106700

// Old style boost type_erasure member fucntion concept definition
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_async)_read, async_read, 3)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_async_write), async_write, 3)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_write), write, 2)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_post), post, 1)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_lowest_layer), lowest_layer, 0)
BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_close), close, 1)

#endif // BOOST_VERSION >= 106700

namespace mqtt {

namespace as = boost::asio;
using namespace boost::type_erasure;

/**
 * @brief type alias of the type erased socket
 * - mqtt::socket is a type erased socket.
 * - shared_ptr of any classes that have listed functions (or matching funtion template)
 *   can be used as the initializer of mqtt::socket.
 * - The class template endpoint uses mqtt::socket via listed interface.
 * - lowest_layer is provided for users to configure the socket (e.g. set delay, buffer size, etc)
 *
 */
using socket = shared_any<
    mpl::vector<
        destructible<>,
        has_async_read<void(as::mutable_buffer, std::function<void(boost::system::error_code const&, std::size_t)>)>,
        has_async_write<void(std::vector<as::const_buffer>, std::function<void(boost::system::error_code const&, std::size_t)>)>,
        has_write<std::size_t(std::vector<as::const_buffer>, boost::system::error_code&)>,
        has_post<void(std::function<void()>)>,
        has_lowest_layer<as::basic_socket<as::ip::tcp>&()>,
        has_close<void(boost::system::error_code&)>
    >
>;

} // namespace mqtt

#endif // MQTT_TYPE_ERASED_SOCKET_HPP

@jonesmz
Copy link
Contributor Author

jonesmz commented Aug 22, 2019

I tried to do the same earlier.

Unfortunately your test file given above results in this error, instead:

mqtt_cpp/include/mqtt/type_erased_socket.hpp:36: error: macro "BOOST_PP_SEQ_ELEM_III" requires 2 arguments, but only 1 given
 BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_async)_read, async_read, 3)
 ^~~~~~~~~~~~~~~~~~~

I am attempting to upgrade to boost 1.70, which will resolve the problem for me (I think?)

But you may still prefer to support boost < 1.67, and I am happy to help investigate that.

@redboltz
Copy link
Owner

Sorry

BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_async)_read, async_read, 3)

should be

BOOST_TYPE_ERASURE_MEMBER((mqtt)(has_async_read), async_read, 3)

Could you try again?

@jonesmz
Copy link
Contributor Author

jonesmz commented Aug 22, 2019

That appears to fix the first problem!!! Wonderful.

Now there's a new problem :-)

mqtt_cpp/include/mqtt/type_erased_socket.hpp:66: error: wrong number of template arguments (1, should be 2)
         has_lowest_layer<as::basic_socket<as::ip::tcp>&()>,
                                                      ^

@redboltz
Copy link
Owner

Could you replace

        has_lowest_layer<as::basic_socket<as::ip::tcp>&()>,

with

        has_lowest_layer<as::ip::tcp::socket::lowest_layer_type&()>,

?

@jonesmz
Copy link
Contributor Author

jonesmz commented Aug 22, 2019

That appears to have fixed it!

I still have plenty of other compiler errors in my code that i need to fix, but we appear to have fixed the boost 1.67 problem!

@redboltz
Copy link
Owner

Thank you for checking. I will send a PR to fix the problem you reported.

@redboltz
Copy link
Owner

Fixed by #347.

@ropieur
Copy link

ropieur commented Sep 10, 2019

I got the master branch and I encounter the same issue with boost 1.70.0
The error disappears, when forcing for version < 1.67 as follows at mqtt/type_erased_socket.hpp:20
#if 0 // BOOST_VERSION >= 106700

@redboltz
Copy link
Owner

@ropieur , the compile error isn't reproduced on my environment.
I tested on 1.70.0 and 1.71.0.
I cleaned build directory each time (using rm -rf * , not make clean).
Could you try this?

@ropieur
Copy link

ropieur commented Sep 11, 2019

@redboltz,
I cleaned up all my environment and build from scratch, but the issue still persists.
FYI, I am using g++ 7.4.0 under ubuntu 18.04.
Also, I added the following lines to verify the boost version

#include <boost/preprocessor/stringize.hpp>
#pragma message "boost version is " BOOST_PP_STRINGIZE(BOOST_VERSION)

Output

...mqtt_cpp/obj/include/mqtt/type_erased_socket.hpp:21:69: note: #pragma message: boost version is 107000

@redboltz
Copy link
Owner

@ropieur , the error message you got is the same as follows ?

mqtt_cpp/include/mqtt/type_erased_socket.hpp:23: error: macro "BOOST_PP_SEQ_ELEM_III" requires 2 arguments, but only 1 given
BOOST_TYPE_ERASURE_MEMBER(has_async_read, async_read)
^~~~~~~~~~~~~~~~~~~

@ropieur
Copy link

ropieur commented Sep 11, 2019

@redboltz,
I got the following error:

mqtt_cpp/obj/include/mqtt/type_erased_socket.hpp:25:1: error: ISO C++11 requires at least one argument for the "..." in a variadic macro
 BOOST_TYPE_ERASURE_MEMBER(has_async_read, async_read)
 ^~~~~~~~~~~~~~

@redboltz redboltz reopened this Sep 12, 2019
@redboltz
Copy link
Owner

@ropieur , it is different error from the error first reported.

I reproduced the error, see
https://wandbox.org/permlink/goH0ctebZGtsBfCk

It is caused by pedantic flags. So Boost.TypeErasure new macro seems to use out of standard expansion. I guess you set the flag.

Could you try compile without pedantic flag?
I just want to know what is the reason of the error.

I know setting pedantic flag is reasonable.
After your checked, I will remove new version macros.

@ropieur
Copy link

ropieur commented Sep 12, 2019

@redboltz,
I confirm that we use pedantic flag. I temporarily disabled it locally in my build environment and the compilation succeeded. But I can't definitely not workaround it for code production due to internal policies.

@redboltz
Copy link
Owner

@ropieur , thank you for confirming.

Of course, I don't enforce removing pedantic flag. I will send the PR to fix the issue. Please wait a moment.

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

3 participants