Boost C++ Libraries: Ticket #6943: gcc 4.7 issue in combination with intrusive_ptr_add_ref and intrusive_ptr_release (boost_1_49_0/boost/intrusive_ptr.hpp - boost_1_49_0/boost/smart_ptr/intrusive_ptr.hpp ) https://svn.boost.org/trac10/ticket/6943 <p> The code of scummvm-tools ( <a class="ext-link" href="http://www.scummvm.org/downloads/#tools"><span class="icon">​</span>http://www.scummvm.org/downloads/#tools</a> ) has been build accoring to this example. <a class="ext-link" href="http://www.codeproject.com/Articles/8394/Smart-Pointers-to-boost-your-code#intrusive_ptr%20-%20lightweight%20shared%20pointer"><span class="icon">​</span>http://www.codeproject.com/Articles/8394/Smart-Pointers-to-boost-your-code#intrusive_ptr%20-%20lightweight%20shared%20pointer</a> </p> <p> &lt;fails with&gt; g++ -MMD -MF "decompiler/.deps/disassembler.d" -MQ "decompiler/disassembler.o" -MP -Wall -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -g -ansi -W -Wno-unused-parameter -Wno-empty-body -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reor der -Wpointer-arith -Wcast-qual -Wshadow -Wnon-virtual-dtor -Wwrite-strings -fcheck-new -DHAVE_CONFIG_H -DPOSIX -I. -I. -c decompiler/disassembler.cpp -o decompiler/disassembler.o In file included from decompiler/instruction.h:30:0, </p> <blockquote> <p> from decompiler/disassembler.h:29, from decompiler/disassembler.cpp:23: </p> </blockquote> <p> /usr/include/boost/smart_ptr/intrusive_ptr.hpp: In instantiation of 'boost::intrusive_ptr&lt;T&gt;::intrusive_ptr(const boost::intrusive_ptr&lt;T&gt;&amp;) [with T = Value; boost::intrusive_ptr&lt;T&gt; = boost::intrusive_ptr&lt;Value&gt;]': decompiler/value.h:335:90: required from here /usr/include/boost/smart_ptr/intrusive_ptr.hpp:91:23: error: 'intrusive_ptr_add_ref' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive] In file included from decompiler/instruction.h:33:0, </p> <blockquote> <p> from decompiler/disassembler.h:29, from decompiler/disassembler.cpp:23: </p> </blockquote> <p> decompiler/refcounted.h:52:13: note: 'void boost::intrusive_ptr_add_ref(<a class="missing wiki">RefCounted</a>*)' declared here, later in the translation unit In file included from decompiler/instruction.h:30:0, </p> <blockquote> <p> from decompiler/disassembler.h:29, from decompiler/disassembler.cpp:23: </p> </blockquote> <p> /usr/include/boost/smart_ptr/intrusive_ptr.hpp: In instantiation of 'boost::intrusive_ptr&lt;T&gt;::~intrusive_ptr() [with T = Value]': decompiler/value.h:335:90: required from here /usr/include/boost/smart_ptr/intrusive_ptr.hpp:96:23: error: 'intrusive_ptr_release' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive] In file included from decompiler/instruction.h:33:0, </p> <blockquote> <p> from decompiler/disassembler.h:29, from decompiler/disassembler.cpp:23: </p> </blockquote> <p> decompiler/refcounted.h:59:13: note: 'void boost::intrusive_ptr_release(<a class="missing wiki">RefCounted</a>*)' declared here, later in the translation unit make: <strong>* [decompiler/disassembler.o] Error 1 &lt;/fails with&gt; <a class="ext-link" href="https://build.opensuse.org/package/live_build_log?arch=i586&amp;package=scummvm-tools&amp;project=games&amp;repository=openSUSE_Factory"><span class="icon">​</span>https://build.opensuse.org/package/live_build_log?arch=i586&amp;package=scummvm-tools&amp;project=games&amp;repository=openSUSE_Factory</a> </strong></p> <p> It was OK until gcc 4.7. As gcc 4.7 is much more strict the build of the code doesn't work any more. </p> <p> I suspect boost itself as no (active) functions <em> void intrusive_ptr_add_ref(T * p); </em> void intrusive_ptr_release(T * p); In boost_1_49_0/boost/smart_ptr/intrusive_ptr.hpp </p> <p> Searching the internet shows that more programs have this issue. It's not unique for scummvm-tools, they solved it, for the time being, with "-fpermissive" which IMHO isn't the correct way. <a class="ext-link" href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672033"><span class="icon">​</span>http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672033</a> <a class="ext-link" href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672397"><span class="icon">​</span>http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672397</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6943 Trac 1.4.3 safety0ff.bugz@… Fri, 15 Jun 2012 17:12:05 GMT <link>https://svn.boost.org/trac10/ticket/6943#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6943#comment:1</guid> <description> <p> I had the same error/issue. My code had the form: </p> <pre class="wiki">// Header 1 class SomeClass; namespace boost { void intrusive_ptr_add_ref(SomeClass* psRPFT); void intrusive_ptr_release(SomeClass* psRPFT); }; class SomeClass { // stuff, including a private variable called reference_count friend void ::boost::intrusive_ptr_add_ref(SomeClass* psSC); friend void ::boost::intrusive_ptr_release(SomeClass* psSC); }; namespace boost { inline void intrusive_ptr_add_ref(SomeClass* psSC) { ++(psSC-&gt;reference_count); } inline void intrusive_ptr_release(SomeClass* psSC) { --(psSC-&gt;reference_count); } }; // Header 2 // include Header 1 using boost::intrusive_ptr; // Source file 2 // Include header 2 and do something that invokes the copy constructor of intrusive_ptr </pre><p> My solution was to change: </p> <pre class="wiki">using boost::intrusive_ptr; </pre><p> to </p> <pre class="wiki">using boost::intrusive_ptr; using boost::intrusive_ptr_add_ref; using boost::intrusive_ptr_release; </pre><p> It this was slightly unexpected for me.<br /> It compiled without the change on gcc 4.5.3 but would not on clang 3.1 and gcc 4.7.0 </p> <p> Not sure if it is a bug (would like clarification.) </p> </description> <category>Ticket</category> </item> <item> <author>safety0ff.bugz@…</author> <pubDate>Fri, 15 Jun 2012 17:13:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6943#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6943#comment:2</guid> <description> <p> psRPFT should be psSC in previous comment. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sun, 17 Jun 2012 06:34:42 GMT</pubDate> <title>owner, component changed https://svn.boost.org/trac10/ticket/6943#comment:3 https://svn.boost.org/trac10/ticket/6943#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Ion Gaztañaga</span> to <span class="trac-author">Peter Dimov</span> </li> <li><strong>component</strong> <span class="trac-field-old">intrusive</span> → <span class="trac-field-new">smart_ptr</span> </li> </ul> <p> Changing componente as intrusive_ptr belongs to smart_ptr. I don't think it's a bug, the standard requires a previous declaration. You should include boost/intrusive_ptr.hpp before calling boost::intrusive_ptr_add_ref. </p> Ticket safety0ff.bugz@… Sun, 17 Jun 2012 07:00:12 GMT attachment set https://svn.boost.org/trac10/ticket/6943 https://svn.boost.org/trac10/ticket/6943 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">intrusive.cpp</span> </li> </ul> <p> Reduced example of the issue </p> Ticket Peter Dimov Sun, 17 Jun 2012 10:37:55 GMT <link>https://svn.boost.org/trac10/ticket/6943#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6943#comment:4</guid> <description> <p> You should define intrusive_ptr_add_ref and intrusive_ptr_release in the namespace of the class, not in namespace boost. </p> </description> <category>Ticket</category> </item> <item> <author>safety0ff.bugz@…</author> <pubDate>Sun, 17 Jun 2012 17:35:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6943#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6943#comment:5</guid> <description> <p> This can be closed (that article contains bad information.) </p> <p> Thanks for clearing that up. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 31 Oct 2012 20:06:54 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6943#comment:6 https://svn.boost.org/trac10/ticket/6943#comment:6 <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">invalid</span> </li> </ul> Ticket