Bug 50423

Summary: error: ‘getpid’ was not declared in this scope
Product: gcc Reporter: Jack Howarth <howarth.at.gcc>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P3    
Version: 4.7.0   
Target Milestone: ---   
Host: x86_64-apple-darwin11 Target: x86_64-apple-darwin11
Build: x86_64-apple-darwin11 Known to work:
Known to fail: Last reconfirmed:
Attachments: bzip2 compressed preprocessed source for common/semaphore.cc

Description Jack Howarth 2011-09-15 17:54:45 UTC
Created attachment 25294 [details]
bzip2 compressed preprocessed source for common/semaphore.cc

Current gcc trunk produces a compile time error for common/semaphore.cc in xplor-nih 2.27...

g++-fsf-4.7 -c semaphore.cc -O3 -ffast-math -funroll-loops -g -fpermissive  -DX_MMAP_FLAGS=0 -DFORTRAN_INIT -fno-common  -DDARWIN -D_REENTRANT -DNDEBUG  -I/Users/howarth/xplor-nih-2.27/common/ -I/Users/howarth/xplor-nih-2.27/arch/Darwin_11_x86_64/include -I/Users/howarth/xplor-nih-2.27/CDSlib -I/Users/howarth/xplor-nih-2.27/intVar -I/Users/howarth/xplor-nih-2.27/pcre -DCPLUSPLUS -DUSE_CDS_NAMESPACE -I/Users/howarth/xplor-nih-2.27/common/ -I/Users/howarth/xplor-nih-2.27/arch/Darwin_11_x86_64/include
semaphore.cc: In constructor ‘CDS::Semaphore::Semaphore(bool)’:
semaphore.cc:111:30: error: ‘getpid’ was not declared in this scope
semaphore.cc: In destructor ‘CDS::Semaphore::~Semaphore()’:
semaphore.cc:124:36: error: ‘getpid’ was not declared in this scope
semaphore.cc:126:9: warning: deleting ‘void*’ is undefined [enabled by default]

which doesn't occur with gcc-4_6-branch...

[MacPro:~/xplor-nih-2.27/common/bin.Darwin_11_x86_64] howarth% g++-fsf-4.6  -c semaphore.cc -O3 -ffast-math -funroll-loops -g -fpermissive  -DX_MMAP_FLAGS=0 -DFORTRAN_INIT -fno-common  -DDARWIN -D_REENTRANT -DNDEBUG  -I/Users/howarth/xplor-nih-2.27/common/ -I/Users/howarth/xplor-nih-2.27/arch/Darwin_11_x86_64/include -I/Users/howarth/xplor-nih-2.27/CDSlib -I/Users/howarth/xplor-nih-2.27/intVar -I/Users/howarth/xplor-nih-2.27/pcre -DCPLUSPLUS -DUSE_CDS_NAMESPACE -I/Users/howarth/xplor-nih-2.27/common/ -I/Users/howarth/xplor-nih-2.27/arch/Darwin_11_x86_64/include
semaphore.cc: In destructor ‘CDS::Semaphore::~Semaphore()’:
semaphore.cc:126:9: warning: deleting ‘void*’ is undefined [enabled by default]
Comment 1 Jack Howarth 2011-09-15 17:57:08 UTC
Attached bzip2 compressed preprocessed source for common/semaphore.cc reproduces this issue...

[MacPro:~/xplor-nih-2.27/common/bin.Darwin_11_x86_64] howarth% g++-fsf-4.7 -c semaphore.ii -O3 -ffast-math -funroll-loops -g -fpermissive -DX_MMAP_FLAGS=0 -DFORTRAN_INIT -fno-common -DDARWIN -D_REENTRANT -DNDEBUGsemaphore.cc: In constructor ‘CDS::Semaphore::Semaphore(bool)’:semaphore.cc:111:30: error: ‘getpid’ was not declared in this scope
semaphore.cc: In destructor ‘CDS::Semaphore::~Semaphore()’:
semaphore.cc:124:36: error: ‘getpid’ was not declared in this scope
semaphore.cc:126:9: warning: deleting ‘void*’ is undefined [enabled by default]
Comment 2 Jack Howarth 2011-09-15 17:57:45 UTC
Note that -fpermissive doesn't eliminate the regression.
Comment 3 Andrew Pinski 2011-09-15 18:01:34 UTC
This is expected you are not including unistd.h in your source which is required if you want to use getpid.  It was a bug before GCC 4.7 that some of the C++ headers included that header file.
Comment 4 Jonathan Wakely 2011-09-16 09:34:31 UTC
As documented at http://gcc.gnu.org/gcc-4.7/changes.html

"Avoid polluting the global namespace by inclusion of <unistd.h>."