Boost C++ Libraries: Ticket #6655: Inclusion of <boost/signals2.hpp> causes valid code to fail to compile with Clang https://svn.boost.org/trac10/ticket/6655 <p> The following well-formed program does not compile with Clang 3.1 (from trunk): </p> <pre class="wiki">#include &lt;memory&gt; #include &lt;boost/signals2.hpp&gt; int main() { std::shared_ptr&lt;int&gt; s; } </pre><p> The error message is: </p> <pre class="wiki">signals2-bug.cpp:6:26: error: implicit instantiation of undefined template 'std::shared_ptr&lt;int&gt;' std::shared_ptr&lt;int&gt; s; ^ /home/alexander/usr/local/include/boost/signals2/detail/foreign_ptr.hpp:24:30: note: template is declared here template&lt;typename T&gt; class shared_ptr; ^ </pre><p> The header boost/signals2/detail/foreign_ptr.hpp declares two names in the std:: namespace: </p> <pre class="wiki">#if !defined(BOOST_INTEL_STDCXX0X) namespace std { template&lt;typename T&gt; class shared_ptr; template&lt;typename T&gt; class weak_ptr; } #endif </pre><p> which is undefined behaviour, according to the Standard 17.6.4.2.1: </p> <blockquote> <p> The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std unless otherwise specified. A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited. </p> </blockquote> <p> The compilation succeeds, if either the #include of &lt;boost/signals2.hpp&gt; is removed, or the offending lines are commented out. </p> <p> Please remove the offending lines from the header. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6655 Trac 1.4.3 Michel Morin <mimomorin@…> Tue, 06 Mar 2012 11:40:10 GMT <link>https://svn.boost.org/trac10/ticket/6655#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6655#comment:1</guid> <description> <blockquote class="citation"> <p> The header boost/signals2/detail/foreign_ptr.hpp declares two names in the std:: namespace which is undefined behaviour, according to the Standard 17.6.4.2.1 </p> </blockquote> <p> Yep. It's not standard-conforming to forward-declare the standard library types (though some standard libraries allow it). <code>libc++</code> uses an inline namespace, and so forward declarations in namespace <code>std</code> causes compile errors. </p> <p> <br /> </p> <blockquote class="citation"> <p> Please remove the offending lines from the header. </p> </blockquote> <p> The solution is to remove the forward declarations and to include <code>&lt;memory&gt;</code>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Frank Mori Hess</dc:creator> <pubDate>Sat, 10 Mar 2012 15:10:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6655#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6655#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/77289" title="Try to deal with C++11 (or not) compilers a little better, so we can ...">[77289]</a>) Try to deal with C++11 (or not) compilers a little better, so we can avoid standard violation in foreign_ptr.hpp. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6655" title="#6655: Bugs: Inclusion of &lt;boost/signals2.hpp&gt; causes valid code to fail to compile ... (closed: fixed)">#6655</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Frank Mori Hess</dc:creator> <pubDate>Thu, 05 Jul 2012 01:44:39 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6655#comment:3 https://svn.boost.org/trac10/ticket/6655#comment:3 <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> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/79273" title="Merge from trunk. Fixes #6655 ">[79273]</a>) Merge from trunk. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6655" title="#6655: Bugs: Inclusion of &lt;boost/signals2.hpp&gt; causes valid code to fail to compile ... (closed: fixed)">#6655</a> </p> Ticket