Boost C++ Libraries: Ticket #5631: nvcc's pre-processor breaks boost/lexical_cast.hpp https://svn.boost.org/trac10/ticket/5631 <p> The <code>nvcc</code> compiler fails to compile a trivial file which just <code>#include</code>s the <code>boost/lexical_cast.hpp</code> header. <code>g++</code> compiles the file correctly. </p> <pre class="wiki">rjw57@spica:~$ cat foo.cpp #include &lt;boost/lexical_cast.hpp&gt; rjw57@spica:~$ cat foo.cu #include &lt;boost/lexical_cast.hpp&gt; rjw57@spica:~$ /usr/bin/g++-4.4 -c foo.cpp rjw57@spica:~$ /usr/bin/nvcc --compiler-bindir=/usr/bin/g++-4.4 -c foo.cu /usr/include/boost/lexical_cast.hpp(352): error: expected an expression 1 error detected in the compilation of "/tmp/tmpxft_00001520_00000000-4_foo.cpp1.ii". </pre><p> The problem is with <code>nvcc</code>'s pre-processor which can be observed by using <code>-E</code> and grepping for <code>// == 1</code> in the output: </p> <pre class="wiki">rjw57@spica:~$ /usr/bin/g++-4.4 -E -o foo-gcc.i foo.cpp rjw57@spica:~$ /usr/bin/nvcc --compiler-bindir=/usr/bin/g++-4.4 -E -o foo-nvcc.i foo.cu rjw57@spica:~$ ack-grep '\/\/ == 1' foo*.i foo-nvcc.i 73304: static const std::size_t value = std::numeric_limits&lt;Source&gt;::is_signed + std::numeric_limits&lt;Source&gt;::is_specialized + // == 1 std::numeric_limits&lt;Source&gt;::digits10 * 2; </pre><p> The <code>nvcc</code> pre-processor does not strip comments from the input to the compiler and appears to be removing new-lines. The <code>gcc</code> compiler does strip the comments. </p> <p> This is possibly a bug in <code>nvcc</code> but I suggest a workaround could be put into boost itself without too much pain. Also I suspect it'd take a standards lawyer to work out who is in the wrong here. </p> <p> The troublesome line (number 345 in 1.4.2) is in the <code>boost/lexical_cast.hpp</code> file. This problem is still present in the SVN trunk. </p> <pre class="wiki">... template&lt;class Source&gt; struct lcast_src_length_integral { #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS BOOST_STATIC_CONSTANT(std::size_t, value = std::numeric_limits&lt;Source&gt;::is_signed + std::numeric_limits&lt;Source&gt;::is_specialized + // == 1 std::numeric_limits&lt;Source&gt;::digits10 * 2 ); #else BOOST_STATIC_CONSTANT(std::size_t, value = 156); BOOST_STATIC_ASSERT(sizeof(Source) * CHAR_BIT &lt;= 256); #endif }; ... </pre><p> A suggested workaround is removing the C++-style comment or replacing it with a C-style one? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5631 Trac 1.4.3 Rich Wareham <rjw57@…> Thu, 23 Jun 2011 09:04:39 GMT <link>https://svn.boost.org/trac10/ticket/5631#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5631#comment:1</guid> <description> <p> My local friendly standards lawyer points out it is a problem with nvcc (comments should be stripped before processing macros apparently) but nonetheless, it seems that boost could defensively code around this issue. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Fri, 12 Aug 2011 17:19:32 GMT</pubDate> <title>owner, status, milestone changed https://svn.boost.org/trac10/ticket/5631#comment:2 https://svn.boost.org/trac10/ticket/5631#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">nasonov</span> to <span class="trac-author">Antony Polukhin</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.48.0</span> </li> </ul> Ticket Antony Polukhin Fri, 12 Aug 2011 17:35:58 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5631#comment:3 https://svn.boost.org/trac10/ticket/5631#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/73707" title="FIxes #5631 Workaround for nvcc bug">[73707]</a>) FIxes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5631" title="#5631: Bugs: nvcc's pre-processor breaks boost/lexical_cast.hpp (closed: fixed)">#5631</a> Workaround for nvcc bug </p> Ticket Antony Polukhin Fri, 12 Aug 2011 17:45:36 GMT <link>https://svn.boost.org/trac10/ticket/5631#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5631#comment:4</guid> <description> <p> Great thanks for testing on nvcc! <br /> Sorry for not responding sooner. If you find any new bugs in lexical_cast, report them and put my name in "Owned by:" field. </p> <p> Does nvcc now fails on some other <code>//</code>? Does now lexical_cast.hpp compiles on nvcc? </p> </description> <category>Ticket</category> </item> </channel> </rss>