Opened 13 years ago

Closed 13 years ago

#3335 closed Feature Requests (duplicate)

boost::threads does not compile with gcc -fno-exceptions

Reported by: Andrew Chittenden <andyc@…> Owned by: Anthony Williams
Milestone: Boost 1.43.0 Component: thread
Version: Boost 1.39.0 Severity: Not Applicable
Keywords: Cc: nigels@…

Description

The following program fails to compile:

--snip #define BOOST_NO_EXCEPTIONS

#include <boost/thread/mutex.hpp>

int foo;

int fn(boost::mutex& pMutex) {

boost::mutex::scoped_lock lock(pMutex); return foo;

}

--snip

It fails:

# g++ -fno-exceptions -I/home/andyc/work/3rdParty/boost_1_39_0 -c -o test.o test.cpp In file included from /home/andyc/work/3rdParty/boost_1_39_0/boost/thread/mutex.hpp:16,

from test.cpp:3:

/home/andyc/work/3rdParty/boost_1_39_0/boost/thread/pthread/mutex.hpp: In constructor ?boost::mutex::mutex()?: /home/andyc/work/3rdParty/boost_1_39_0/boost/thread/pthread/mutex.hpp:40: error: exception handling disabled, use -fexceptions to enable

There are other exceptions in boost/thread/locks.hpp that aren't surrounded by #ifndef BOOST_NO_EXCEPTIONS too. I've attached a patch to fix those.

Attachments (3)

locks.hpp.patch (3.1 KB ) - added by Andrew Chittenden <andyc@…> 13 years ago.
patch to boost/thread/locks.hpp to make it BOOST_NO_EXCEPTIONS aware.
mutex.hpp.patch (973 bytes ) - added by Andrew Chittenden <andyc@…> 13 years ago.
patch to boost/thread/pthread/mutex.hpp to make it BOOST_NO_EXCEPTIONS aware.
once.hpp.patch (1023 bytes ) - added by Andrew Chittenden <andyc@…> 13 years ago.
patch to boost/thread/pthread/once.hpp to make it BOOST_NO_EXCEPTIONS aware.

Download all attachments as: .zip

Change History (7)

by Andrew Chittenden <andyc@…>, 13 years ago

Attachment: locks.hpp.patch added

patch to boost/thread/locks.hpp to make it BOOST_NO_EXCEPTIONS aware.

by Andrew Chittenden <andyc@…>, 13 years ago

Attachment: mutex.hpp.patch added

patch to boost/thread/pthread/mutex.hpp to make it BOOST_NO_EXCEPTIONS aware.

comment:1 by Steven Watanabe, 13 years ago

Component: Nonethread
Owner: set to Anthony Williams

comment:2 by Andrew Chittenden <andyc@…>, 13 years ago

using once.hpp also fails to compile:

<pre> --snip #define BOOST_NO_EXCEPTIONS

#include <boost/thread/once.hpp>

boost::once_flag once = BOOST_ONCE_INIT;

bool initialised = false;

void testOnceInit() {

assert(!initialised); initialised = true;

}

struct ConstructOnce {

ConstructOnce() {

boost::call_once(&testOnceInit, once);

}

};

ConstructOnce first; ConstructOnce second;

--snip # g++ -Wall -fno-exceptions -I/home/andyc/work/3rdParty/boost_1_39_0 -c -o testonce.o testonce.cpp /home/andyc/work/3rdParty/boost_1_39_0/boost/thread/pthread/once.hpp: In function ?void boost::call_once(boost::once_flag&, Function) [with Function = void (*)()]?: /home/andyc/work/3rdParty/boost_1_39_0/boost/thread/once.hpp:27: instantiated from here /home/andyc/work/3rdParty/boost_1_39_0/boost/thread/pthread/once.hpp:66: error: exception handling disabled, use -fexceptions to enable </pre>

by Andrew Chittenden <andyc@…>, 13 years ago

Attachment: once.hpp.patch added

patch to boost/thread/pthread/once.hpp to make it BOOST_NO_EXCEPTIONS aware.

comment:3 by viboes, 13 years ago

Severity: ProblemNot Applicable
Type: BugsFeature Requests

Your patches just protect the throw statements, but what would be the behavior of the application with your patches. I think Boost.Threads has not an interface that allows to use it without exceptions, so I will consider this a feature request and not a Bug.

comment:4 by nigels@…, 13 years ago

Cc: nigels@… added
Milestone: Boost 1.40.0Boost 1.43.0
Resolution: duplicate
Status: newclosed

Marking this as a duplicate of #2100 - thread fails to compile with -fno-exceptions.

The good news is that this is just about resolved in boost svn trunk.

Note: See TracTickets for help on using tickets.