Boost C++ Libraries: Ticket #13372: Boost Preprocessing: compiler error: macro "BOOST_PP_VARIADIC_ELEM_2" requires 4 arguments, but only 2 given https://svn.boost.org/trac10/ticket/13372 <p> The following code produces the following compiler error when compiled with gcc 7.2.0 or clang 3.8.0 </p> <pre class="wiki">error: macro "BOOST_PP_VARIADIC_ELEM_2" requires 4 arguments, but only 2 given </pre><pre class="wiki">#include &lt;boost/preprocessor.hpp&gt; #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; } </pre><p> (online demo: <a class="ext-link" href="http://coliru.stacked-crooked.com/a/f01351ee7a0ca55d"><span class="icon">​</span>http://coliru.stacked-crooked.com/a/f01351ee7a0ca55d</a> ) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13372 Trac 1.4.3 Dmitry B <d4qcdes@…> Sat, 27 Jan 2018 09:10:21 GMT <link>https://svn.boost.org/trac10/ticket/13372#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13372#comment:1</guid> <description> <p> It seems that the reason is </p> <pre class="wiki">BOOST_PP_TUPLE_ELEM(2, (El1)) </pre><p> doesn't compile with an error </p> <pre class="wiki">error: macro "BOOST_PP_VARIADIC_ELEM_2" requires 4 arguments, but only 2 given </pre><p> in the same time </p> <pre class="wiki">BOOST_PP_TUPLE_ELEM(2, (El1,)) </pre><p> compiles </p> <p> so, I have simplified the repro a bit: </p> <pre class="wiki">#include &lt;boost/preprocessor.hpp&gt; #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; } </pre> </description> <category>Ticket</category> </item> </channel> </rss>