Boost C++ Libraries: Ticket #6989: BOOST_PP_SEQ_ELEM/BOOST_PP_IF behave differently on different compilers https://svn.boost.org/trac10/ticket/6989 <p> MSVC accepts the following code, but gcc reject it with error message that it is impossible to get second element of sequence with size = 1. The problem is that gcc and clang expand both HANDLE_SIZE_EQ_1 and HANDLE_SIZE_EQ_2 before expanding BOOST_PP_IF. </p> <p> As it turned out MSVC and GCC get different versions of BOOST_PP_SEQ_ELEM. When MSVC get version of BOOST_PP_SEQ_ELEM for GCC it also show warning. </p> <p> See connect.microsoft.com/VisualStudio/feedback/details/743894/possibly-incorrect-macro-expansion-order for details. </p> <p> <em> boost version 1.49 #include &lt;boost/preprocessor/comparison/not_equal.hpp&gt; #include &lt;boost/preprocessor/seq/cat.hpp&gt; #include &lt;boost/preprocessor/seq/elem.hpp&gt; #include &lt;boost/preprocessor/seq/size.hpp&gt; </em></p> <p> #define HANDLE_SIZE_EQ_1(seq) </p> <p> #define HANDLE_SIZE_EQ_2(seq) \ </p> <blockquote> <p> BOOST_PP_SEQ_ELEM(1, seq) </p> </blockquote> <p> #define TEST_IF(seq) \ </p> <blockquote> <p> BOOST_PP_IF(BOOST_PP_NOT_EQUAL(2, BOOST_PP_SEQ_SIZE(seq)) \ , HANDLE_SIZE_EQ_1(seq) \ , HANDLE_SIZE_EQ_2(seq)) </p> </blockquote> <p> TEST_IF((a)) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6989 Trac 1.4.3 Edward Diener Sun, 17 May 2015 03:07:15 GMT <link>https://svn.boost.org/trac10/ticket/6989#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6989#comment:1</guid> <description> <p> Gcc is correct and MSVC is wrong. The proper way to write such code is: </p> <pre class="wiki"> #define HANDLE_SIZE_EQ_1(seq) #define HANDLE_SIZE_EQ_2(seq) \ BOOST_PP_SEQ_ELEM(1, seq) #define TEST_IF(seq) \ BOOST_PP_IF(BOOST_PP_NOT_EQUAL(2, BOOST_PP_SEQ_SIZE(seq)), \ HANDLE_SIZE_EQ_1, \ HANDLE_SIZE_EQ_2) \ (seq) TEST_IF((a)) </pre><p> The code will work on VC++ and gcc. This is not a bug in the preprocessor but in your code. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Edward Diener</dc:creator> <pubDate>Sun, 17 May 2015 03:07:22 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6989#comment:2 https://svn.boost.org/trac10/ticket/6989#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket