Opened 5 years ago

Last modified 5 years ago

#13372 new Bugs

Boost Preprocessing: compiler error: macro "BOOST_PP_VARIADIC_ELEM_2" requires 4 arguments, but only 2 given

Reported by: Dmitrii B <d4qcdes@…> Owned by: No-Maintainer
Milestone: To Be Determined Component: preprocessor
Version: Boost 1.64.0 Severity: Problem
Keywords: Cc:

Description

The following code produces the following compiler error when compiled with gcc 7.2.0 or clang 3.8.0

error: macro "BOOST_PP_VARIADIC_ELEM_2" requires 4 arguments, but only 2 given
#include <boost/preprocessor.hpp>

#define CREATE_ENUM_ELEMENT(elementTuple)												\
    BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_TUPLE_SIZE(elementTuple), 3),                   \
        BOOST_PP_TUPLE_ELEM(0, elementTuple) = BOOST_PP_TUPLE_ELEM(2, elementTuple),    \
        BOOST_PP_TUPLE_ELEM(0, elementTuple)                                            \
    ),

enum class MyEnum {
	CREATE_ENUM_ELEMENT((El1))
};

int main() {
	return 0;
}

(online demo: http://coliru.stacked-crooked.com/a/f01351ee7a0ca55d )

Change History (1)

comment:1 by Dmitry B <d4qcdes@…>, 5 years ago

It seems that the reason is

BOOST_PP_TUPLE_ELEM(2, (El1))

doesn't compile with an error

error: macro "BOOST_PP_VARIADIC_ELEM_2" requires 4 arguments, but only 2 given

in the same time

BOOST_PP_TUPLE_ELEM(2, (El1,))

compiles

so, I have simplified the repro a bit:

#include <boost/preprocessor.hpp>

#define TUPLE_WITH_ONE_ELEMENT_WITHOUT_COMMA_AT_THE_END (a)
#define TUPLE_WITH_ONE_ELEMENT_WITH_COMMA_AT_THE_END (a,)

#define DEFINE_VARIABLE(tupleWithVariable)												\
    BOOST_PP_IF(0,                                                                      \
        BOOST_PP_TUPLE_ELEM(2, tupleWithVariable),                                      \
        BOOST_PP_TUPLE_ELEM(0, tupleWithVariable)                                       \
    )

int DEFINE_VARIABLE(TUPLE_WITH_ONE_ELEMENT_WITHOUT_COMMA_AT_THE_END); // doesn't compile
int DEFINE_VARIABLE(TUPLE_WITH_ONE_ELEMENT_WITH_COMMA_AT_THE_END);

int main() {
	return 0;
}
Note: See TracTickets for help on using tickets.