Falsche Anzahl an Template-Argumenten in Makro von Boost-Test



  • Hallo,

    ich habe vor kurzem ein Upgrade von Ubuntu 16.04 auf Ubuntu 18.04 durchgeführt und seitdem kompiliert ein Teil meines C++-Codes nicht mehr (das könnte allerdings auch nur Zufall sein).

    Hier ein Minimalbeispiel, das nicht kompiliert:

    #include <boost/test/unit_test.hpp>
    #include <boost/preprocessor/punctuation/comma.hpp>
    template<unsigned a, unsigned b> struct Tmpl { };
    BOOST_FIXTURE_TEST_CASE( abc, Tmpl<1 BOOST_PP_COMMA() 1> ) { }
    

    Die Fehlermeldung des gcc lautet:

    In file included from /home/ingo/opt/boost-1.68.0/include/boost/test/unit_test.hpp:19,
                     from min_ex.cpp:1:
    min_ex.cpp:4:36: error: wrong number of template arguments (1, should be 2)
     BOOST_FIXTURE_TEST_CASE( abc, Tmpl<1 BOOST_PP_COMMA() 1> ) { }
                                        ^
    /home/ingo/opt/boost-1.68.0/include/boost/test/unit_test_suite.hpp:142:27: note: in definition of macro ‘BOOST_FIXTURE_TEST_CASE_WITH_DECOR’
     struct test_name : public F { void test_method(); };                    \
                               ^
    /home/ingo/opt/boost-1.68.0/include/boost/test/detail/pp_variadic.hpp:35:5: note: in expansion of macro ‘BOOST_TEST_INVOKE_VARIADIC’
         BOOST_TEST_INVOKE_VARIADIC(                                     \
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/ingo/opt/boost-1.68.0/include/boost/test/unit_test_suite.hpp:176:5: note: in expansion of macro ‘BOOST_TEST_INVOKE_IF_N_ARGS’
         BOOST_TEST_INVOKE_IF_N_ARGS( 2,                                     \
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    min_ex.cpp:4:1: note: in expansion of macro ‘BOOST_FIXTURE_TEST_CASE’
     BOOST_FIXTURE_TEST_CASE( abc, Tmpl<1 BOOST_PP_COMMA() 1> ) { }
     ^~~~~~~~~~~~~~~~~~~~~~~
    min_ex.cpp:3:41: note: provided for ‘template<unsigned int a, unsigned int b> struct Tmpl’
     template<unsigned a, unsigned b> struct Tmpl { };
                                             ^~~~
    In file included from /home/ingo/opt/boost-1.68.0/include/boost/test/unit_test.hpp:19,
                     from min_ex.cpp:1:
    /home/ingo/opt/boost-1.68.0/include/boost/test/unit_test_suite.hpp:163:20: error: expected primary-expression before ‘)’ token
             decorators );                                                   \
                        ^
    /home/ingo/opt/boost-1.68.0/include/boost/test/detail/pp_variadic.hpp:27:51: note: in expansion of macro ‘BOOST_FIXTURE_TEST_CASE_WITH_DECOR’
     #  define BOOST_TEST_INVOKE_VARIADIC( tool, ... ) tool (__VA_ARGS__)
                                                       ^~~~
    /home/ingo/opt/boost-1.68.0/include/boost/test/detail/pp_variadic.hpp:35:5: note: in expansion of macro ‘BOOST_TEST_INVOKE_VARIADIC’
         BOOST_TEST_INVOKE_VARIADIC(                                     \
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/ingo/opt/boost-1.68.0/include/boost/preprocessor/control/iif.hpp:25:39: note: in expansion of macro ‘BOOST_PP_IIF_0’
     #    define BOOST_PP_IIF_I(bit, t, f) BOOST_PP_IIF_ ## bit(t, f)
                                           ^~~~~~~~~~~~~
    /home/ingo/opt/boost-1.68.0/include/boost/preprocessor/control/iif.hpp:18:37: note: in expansion of macro ‘BOOST_PP_IIF_I’
     #    define BOOST_PP_IIF(bit, t, f) BOOST_PP_IIF_I(bit, t, f)
                                         ^~~~~~~~~~~~~~
    /home/ingo/opt/boost-1.68.0/include/boost/test/detail/pp_variadic.hpp:36:9: note: in expansion of macro ‘BOOST_PP_IIF’
             BOOST_PP_IIF(                                               \
             ^~~~~~~~~~~~
    /home/ingo/opt/boost-1.68.0/include/boost/test/unit_test_suite.hpp:176:5: note: in expansion of macro ‘BOOST_TEST_INVOKE_IF_N_ARGS’
         BOOST_TEST_INVOKE_IF_N_ARGS( 2,                                     \
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    min_ex.cpp:4:1: note: in expansion of macro ‘BOOST_FIXTURE_TEST_CASE’
     BOOST_FIXTURE_TEST_CASE( abc, Tmpl<1 BOOST_PP_COMMA() 1> ) { }
     ^~~~~~~~~~~~~~~~~~~~~~~
    

    Und hier der Aufruf des gcc:

    g++ -I/home/ingo/opt/boost-1.68.0/include -Wall -c -fmessage-length=0 -std=c++17 -MMD -MP -MF "min_ex.d" -MT "min_ex.o" -o "min_ex.o" "min_ex.cpp"
    

    Ich habe versucht, mir die Ausgabe des Präprozessors anzuschauen, um zu verstehen, wo der Fehler herkommt. Allerdings ist sie schwer zu lesen und meine Hoffnung war, dass jemand anderes schon mal dasselbe Problem hatte. Die letzten beiden Zeilen der Präprozessor-Ausgabe lautet:

    template<unsigned a, unsigned b> struct Tmpl { };
    
    struct abc : public Tmpl<1 { void test_method(); }; static void abc_invoker() { ::boost::unit_test::unit_test_log.set_checkpoint( ::boost::unit_test::const_string( "../src/test/min_ex.cpp", sizeof( "../src/test/min_ex.cpp" ) - 1 ), static_cast<std::size_t>(6), (::boost::wrap_stringstream().ref() << '"' << "abc" << "\" fixture ctor").str() ); abc t; ::boost::unit_test::unit_test_log.set_checkpoint( ::boost::unit_test::const_string( "../src/test/min_ex.cpp", sizeof( "../src/test/min_ex.cpp" ) - 1 ), static_cast<std::size_t>(6), (::boost::wrap_stringstream().ref() << '"' << "abc" << "\" fixture setup").str() ); boost::unit_test::setup_conditional(t); ::boost::unit_test::unit_test_log.set_checkpoint( ::boost::unit_test::const_string( "../src/test/min_ex.cpp", sizeof( "../src/test/min_ex.cpp" ) - 1 ), static_cast<std::size_t>(6), (::boost::wrap_stringstream().ref() << '"' << "abc" << "\" test entry").str() ); t.test_method(); ::boost::unit_test::unit_test_log.set_checkpoint( ::boost::unit_test::const_string( "../src/test/min_ex.cpp", sizeof( "../src/test/min_ex.cpp" ) - 1 ), static_cast<std::size_t>(6), (::boost::wrap_stringstream().ref() << '"' << "abc" << "\" fixture teardown").str() ); boost::unit_test::teardown_conditional(t); ::boost::unit_test::unit_test_log.set_checkpoint( ::boost::unit_test::const_string( "../src/test/min_ex.cpp", sizeof( "../src/test/min_ex.cpp" ) - 1 ), static_cast<std::size_t>(6), (::boost::wrap_stringstream().ref() << '"' << "abc" << "\" fixture dtor").str() ); } struct abc_id {}; static boost::unit_test::ut_detail::auto_test_unit_registrar abc_registrar60( boost::unit_test::make_test_case( &abc_invoker, "abc", "../src/test/min_ex.cpp", 6 ), 1> ); void abc::test_method() { }
    


  • @ingobulla sagte in Falsche Anzahl an Template-Argumenten in Makro von Boost-Test:

    -I/home/ingo/opt/boost-1.68.0/include

    Warum benutzt du nicht die Boostversion aus der Paketverwaltung?



  • @manni66 sagte in Falsche Anzahl an Template-Argumenten in Makro von Boost-Test:

    @ingobulla sagte in Falsche Anzahl an Template-Argumenten in Makro von Boost-Test:

    -I/home/ingo/opt/boost-1.68.0/include

    Warum benutzt du nicht die Boostversion aus der Paketverwaltung?

    Ich hatte die Hoffnung, die neueste Version von Boost zu verwenden, würde das Problem beheben. Davor hatte ich die von Ubuntu zur Verfügung gestellte Version (1.65.0) verwandt und hatte denselben Fehler erhalten.



  • Ich kann das auf Tumbleweed reproduzieren. Ich kenne Boost.Test nicht und kann nicht sgane, ob es gehen müsste.



  • BOOST_FIXTURE_TEST_CASE kann nicht mit template typen umgehen.

    Das makro packt den generieren code vor das comma in der template definition

    eventuell funktioniert ein typedef.

    Sollen die template parameter variieren aber der selbe test durchlaufen werden?
    Dann könnte BOOST_FIXTURE_TEST_CASE_TEMPLATE eine alternative sein. Wobei ich das jetzt nur kurz aus der doku rausgelesen habe und nicht sicher bin ob es das gewünschte bietet


Anmelden zum Antworten