This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/15415] New: _REENTRANT defined if string header included without -pthread


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]