public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15415] New: _REENTRANT defined if string header included without -pthread
@ 2004-05-13 14:54 cludwig at cdc dot informatik dot tu-darmstadt dot de
2004-05-13 14:58 ` [Bug c++/15415] " cludwig at cdc dot informatik dot tu-darmstadt dot de
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: cludwig at cdc dot informatik dot tu-darmstadt dot de @ 2004-05-13 14:54 UTC (permalink / raw)
To: gcc-bugs
Up to gcc 3.3.x, _REENTRANT could be used (on x86 Linux, at least) to determine
at compile time whether the compiler was called with the -pthread option. The
Boost library, e.g., relied on this behaviour to decide if boost::smart_ptr
needs to be made MT safe.
Since gcc 3.4.0, _REENTRANT is defined if you include the C++ standard header
string. (Other headers may cause the symbol to be defined, too; I didn't
check.) This potentially breaks many programs using Boost due to ODR violations
depending on whether the header string was included before the header boost/
config.hpp or not.
The behaviour change between gcc 3.3.x and 3.4.0 is exhibited by the following
"program":
cludwig@lap200:~/C++/gcc3.4/tmp> cat REENTRANT.cc
#if defined(INCLUDE_STRING)
# include <string>
# warning "string header included"
#else
# warning "no header included"
#endif
#if defined(_REENTRANT)
# warning "_REENTRANT is defined"
#else
# warning "_REENTRANT is not defined"
#endif
If you compile it with gcc 3.3.2, everything is as expected:
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -v
Reading specs from /opt/gcc/gcc-3.3.2/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/
specs
Konfiguriert mit: ../gcc-3.3.2/configure --prefix=/opt/gcc/gcc-3.3.2
--enable-threads --enable-version-specific-runtime-libs --enable-languages=c,c+
+ --enable-__cxa_atexit --enable-c-mbchar
Thread model: posix
gcc-Version 3.3.2
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -o /dev/null -c REENTRANT.cc
REENTRANT.cc:5:4: Warnung: #warning "no header included"
REENTRANT.cc:11:4: Warnung: #warning "_REENTRANT is not defined"
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -DINCLUDE_STRING -o /dev/null -c
REENTRANT.cc
REENTRANT.cc:3:4: Warnung: #warning "string header included"
REENTRANT.cc:11:4: Warnung: #warning "_REENTRANT is not defined"
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -pthread -o /dev/null -c REENTRANT.cc
REENTRANT.cc:5:4: Warnung: #warning "no header included"
REENTRANT.cc:9:4: Warnung: #warning "_REENTRANT is defined"
But if you compile it with gcc 3.4.0, _REENTRANT is defined as soon as you
include string:
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -v
Lese Spezifikationen von /opt/gcc/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/
specs
Konfiguriert mit: ../gcc-3.4.0/configure --prefix=/opt/gcc/gcc-3.4.0
--enable-threads=posix --enable-version-specific-runtime-libs
--enable-languages=c,c++ --enable-__cxa_atexit --enable-c-mbchar
--enable-concept-checks --enable-libstdcxx-debug --enable-c99
--enable-libstdcxx-pch
Thread-Modell: posix
gcc-Version 3.4.0
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -o /dev/null -c REENTRANT.cc
REENTRANT.cc:5:4: Warnung: #warning "no header included"
REENTRANT.cc:11:4: Warnung: #warning "_REENTRANT is not defined"
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -DINCLUDE_STRING -o /dev/null -c
REENTRANT.cc
REENTRANT.cc:3:4: Warnung: #warning "string header included"
REENTRANT.cc:9:4: Warnung: #warning "_REENTRANT is defined"
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -pthread -o /dev/null -c REENTRANT.cc
REENTRANT.cc:5:4: Warnung: #warning "no header included"
REENTRANT.cc:9:4: Warnung: #warning "_REENTRANT is defined"
I was able to trace the problem back to a change in lib/gcc/
i686-pc-linux-gnu/3.4.0/include/c++/i686-pc-linux-gnu/bits/gthr-default.h. If I
am not mistaken then this change was discussed in http://gcc.gnu.org/ml/
gcc-patches/2003-07/msg01607.html.
I am not sure whether this problem can be labeled a regression - AFAIK, it was
never documented that _REENTRANT can be used to detect -pthread. But it has the
potential to break a large code base.
In fact, the option -pthread is not documented for x86 / Linux at all. (The
manual's option index mentions it only on the IBM RS/6000 and PowerPC submodel
options page.) This constitutes IMO a documentation bug. Do you want me to file
a separate bug report for this issue?
Regards
Christoph
--
Summary: _REENTRANT defined if string header included without -
pthread
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cludwig at cdc dot informatik dot tu-darmstadt dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15415
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/15415] _REENTRANT defined if string header included without -pthread
2004-05-13 14:54 [Bug c++/15415] New: _REENTRANT defined if string header included without -pthread cludwig at cdc dot informatik dot tu-darmstadt dot de
@ 2004-05-13 14:58 ` cludwig at cdc dot informatik dot tu-darmstadt dot de
2004-05-13 15:08 ` pinskia at gcc dot gnu dot org
2004-05-13 23:15 ` cludwig at cdc dot informatik dot tu-darmstadt dot de
2 siblings, 0 replies; 4+ messages in thread
From: cludwig at cdc dot informatik dot tu-darmstadt dot de @ 2004-05-13 14:58 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cludwig at cdc dot informatik dot tu-darmstadt dot de 2004-05-13 10:08 -------
Created an attachment (id=6274)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=6274&action=view)
test program exhibiting the problem
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15415
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/15415] _REENTRANT defined if string header included without -pthread
2004-05-13 14:54 [Bug c++/15415] New: _REENTRANT defined if string header included without -pthread cludwig at cdc dot informatik dot tu-darmstadt dot de
2004-05-13 14:58 ` [Bug c++/15415] " cludwig at cdc dot informatik dot tu-darmstadt dot de
@ 2004-05-13 15:08 ` pinskia at gcc dot gnu dot org
2004-05-13 23:15 ` cludwig at cdc dot informatik dot tu-darmstadt dot de
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-13 15:08 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-13 10:53 -------
This is a dup of bug 11953, this was an intended change.
*** This bug has been marked as a duplicate of 11953 ***
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15415
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/15415] _REENTRANT defined if string header included without -pthread
2004-05-13 14:54 [Bug c++/15415] New: _REENTRANT defined if string header included without -pthread cludwig at cdc dot informatik dot tu-darmstadt dot de
2004-05-13 14:58 ` [Bug c++/15415] " cludwig at cdc dot informatik dot tu-darmstadt dot de
2004-05-13 15:08 ` pinskia at gcc dot gnu dot org
@ 2004-05-13 23:15 ` cludwig at cdc dot informatik dot tu-darmstadt dot de
2 siblings, 0 replies; 4+ messages in thread
From: cludwig at cdc dot informatik dot tu-darmstadt dot de @ 2004-05-13 23:15 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cludwig at cdc dot informatik dot tu-darmstadt dot de 2004-05-13 12:46 -------
Subject: Re: _REENTRANT defined if string header included without -pthread
On Thu, May 13, 2004 at 10:53:29AM -0000, pinskia at gcc dot gnu dot org wrote:
> This is a dup of bug 11953,
I don't know why I missed #11953. Sorry.
> this was an intended change.
Very well, but I doubt the consequence I complained about (not beeing
able to detect -pthread on x86 / Linux) was intended... Note that the
patch that introduced this change was supposed to solve a problem on
True64 Unix, http://gcc.gnu.org/ml/gcc-patches/2003-07/msg01607.html
does not talk about x86 / Linux at all.
But more important: The solution to #11953 proposed by Benjamin Kosnik
(test for _POSIX_THREADS and check >=0) fails! If I amend my test and
compile it with gcc 3.4.0, I get the following:
cludwig@lap200:~/C++/gcc3.4/tmp> cat REENTRANT.cc
#if defined(INCLUDE_STRING)
# include <string>
# warning "string header included"
#else
# warning "no header included"
#endif
#if defined(_REENTRANT)
# warning "_REENTRANT is defined"
#else
# warning "_REENTRANT is not defined"
#endif
#if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0
# warning "_POSIX_THREADS >= 0"
#elif defined(_POSIX_THREADS)
# warning "_POSIX_THREADS defxined"
#else
# warning "_POSIX_THREADS not defined"
#endif
#include <unistd.h>
#warning "After inclusion of unistd.h:"
#if defined(_REENTRANT)
# warning "_REENTRANT is defined"
#else
# warning "_REENTRANT is not defined"
#endif
#if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0
# warning "_POSIX_THREADS >= 0"
#elif defined(_POSIX_THREADS)
# warning "_POSIX_THREADS defxined"
#else
# warning "_POSIX_THREADS not defined"
#endif
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -o /dev/null -c REENTRANT.cc
REENTRANT.cc:5:4: Warnung: #warning "no header included"
REENTRANT.cc:11:4: Warnung: #warning "_REENTRANT is not defined"
REENTRANT.cc:19:4: Warnung: #warning "_POSIX_THREADS not defined"
REENTRANT.cc:24:2: Warnung: #warning "After inclusion of unistd.h:"
REENTRANT.cc:29:4: Warnung: #warning "_REENTRANT is not defined"
REENTRANT.cc:33:4: Warnung: #warning "_POSIX_THREADS >= 0"
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -DINCLUDE_STRING -o /dev/null -c REENTRANT.cc
REENTRANT.cc:3:4: Warnung: #warning "string header included"
REENTRANT.cc:9:4: Warnung: #warning "_REENTRANT is defined"
REENTRANT.cc:15:4: Warnung: #warning "_POSIX_THREADS >= 0"
REENTRANT.cc:24:2: Warnung: #warning "After inclusion of unistd.h:"
REENTRANT.cc:27:4: Warnung: #warning "_REENTRANT is defined"
REENTRANT.cc:33:4: Warnung: #warning "_POSIX_THREADS >= 0"
ludwig@lap200:~/C++/gcc3.4/tmp> g++ -pthread -o /dev/null -c REENTRANT.cc
REENTRANT.cc:5:4: Warnung: #warning "no header included"
REENTRANT.cc:9:4: Warnung: #warning "_REENTRANT is defined"
REENTRANT.cc:19:4: Warnung: #warning "_POSIX_THREADS not defined"
REENTRANT.cc:24:2: Warnung: #warning "After inclusion of unistd.h:"
REENTRANT.cc:27:4: Warnung: #warning "_REENTRANT is defined"
REENTRANT.cc:33:4: Warnung: #warning "_POSIX_THREADS >= 0"
_POSIX_THREADS is defined only if certain headers are included. It
does not matter at all if -pthread was on the compilers command line.
It seems to me (without looking up any references) that _POSIX_THREADS
indicates whether the *system* offers pthread support. But it's
totally useless if you want to decide whether the current translation
unit is to be built with thread support. (After all, I don't want to
pay for any overhead in a single threaded application, even if both
the compiler and the system are capable of pthread support.)
I therefore don't consider this bug report as resolved yet. There is
no documented way to decide at compile time whether -pthread was on
the command line.
Regards
Christoph
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15415
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-05-13 12:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-13 14:54 [Bug c++/15415] New: _REENTRANT defined if string header included without -pthread cludwig at cdc dot informatik dot tu-darmstadt dot de
2004-05-13 14:58 ` [Bug c++/15415] " cludwig at cdc dot informatik dot tu-darmstadt dot de
2004-05-13 15:08 ` pinskia at gcc dot gnu dot org
2004-05-13 23:15 ` cludwig at cdc dot informatik dot tu-darmstadt dot de
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).