Opened 10 years ago

Closed 10 years ago

#6943 closed Bugs (invalid)

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 )

Reported by: Joop Boonen <joop.boonen@…> Owned by: Peter Dimov
Milestone: Boost 1.49.0 Component: smart_ptr
Version: Boost 1.49.0 Severity: Regression
Keywords: Cc:

Description

The code of scummvm-tools ( http://www.scummvm.org/downloads/#tools ) has been build accoring to this example. http://www.codeproject.com/Articles/8394/Smart-Pointers-to-boost-your-code#intrusive_ptr%20-%20lightweight%20shared%20pointer

<fails with> 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,

from decompiler/disassembler.h:29, from decompiler/disassembler.cpp:23:

/usr/include/boost/smart_ptr/intrusive_ptr.hpp: In instantiation of 'boost::intrusive_ptr<T>::intrusive_ptr(const boost::intrusive_ptr<T>&) [with T = Value; boost::intrusive_ptr<T> = boost::intrusive_ptr<Value>]': 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,

from decompiler/disassembler.h:29, from decompiler/disassembler.cpp:23:

decompiler/refcounted.h:52:13: note: 'void boost::intrusive_ptr_add_ref(RefCounted*)' declared here, later in the translation unit In file included from decompiler/instruction.h:30:0,

from decompiler/disassembler.h:29, from decompiler/disassembler.cpp:23:

/usr/include/boost/smart_ptr/intrusive_ptr.hpp: In instantiation of 'boost::intrusive_ptr<T>::~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,

from decompiler/disassembler.h:29, from decompiler/disassembler.cpp:23:

decompiler/refcounted.h:59:13: note: 'void boost::intrusive_ptr_release(RefCounted*)' declared here, later in the translation unit make: * [decompiler/disassembler.o] Error 1 </fails with> https://build.opensuse.org/package/live_build_log?arch=i586&package=scummvm-tools&project=games&repository=openSUSE_Factory

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.

I suspect boost itself as no (active) functions void intrusive_ptr_add_ref(T * p); void intrusive_ptr_release(T * p); In boost_1_49_0/boost/smart_ptr/intrusive_ptr.hpp

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. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672033 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672397

Attachments (1)

intrusive.cpp (1.0 KB ) - added by safety0ff.bugz@… 10 years ago.
Reduced example of the issue

Download all attachments as: .zip

Change History (7)

comment:1 by safety0ff.bugz@…, 10 years ago

I had the same error/issue. My code had the form:

// 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->reference_count);
	}

	inline void intrusive_ptr_release(SomeClass* psSC)
	{
		--(psSC->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

My solution was to change:

using boost::intrusive_ptr;

to

using boost::intrusive_ptr;
using boost::intrusive_ptr_add_ref;
using boost::intrusive_ptr_release;

It this was slightly unexpected for me.
It compiled without the change on gcc 4.5.3 but would not on clang 3.1 and gcc 4.7.0

Not sure if it is a bug (would like clarification.)

comment:2 by safety0ff.bugz@…, 10 years ago

psRPFT should be psSC in previous comment.

comment:3 by Ion Gaztañaga, 10 years ago

Component: intrusivesmart_ptr
Owner: changed from Ion Gaztañaga to Peter Dimov

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.

by safety0ff.bugz@…, 10 years ago

Attachment: intrusive.cpp added

Reduced example of the issue

comment:4 by Peter Dimov, 10 years ago

You should define intrusive_ptr_add_ref and intrusive_ptr_release in the namespace of the class, not in namespace boost.

comment:5 by safety0ff.bugz@…, 10 years ago

This can be closed (that article contains bad information.)

Thanks for clearing that up.

comment:6 by Peter Dimov, 10 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.