Bug 7602 - C++ header files found in CPLUS_INCLUDE_PATH treated as C headers
Summary: C++ header files found in CPLUS_INCLUDE_PATH treated as C headers
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 3.0.3
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-14 19:56 UTC by s.perkins
Modified: 2003-07-25 17:33 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
foo.tar (283 bytes, application/octet-stream)
2003-05-21 15:17 UTC, s.perkins
Details

Note You need to log in before you can comment on or make changes to this bug.
Description s.perkins 2002-08-14 19:56:01 UTC
On the above platform, functions in C++ header files that are found by g++ via the CPLUS_INCLUDE_PATH, are treated as C functions. This leads to function declaration conflict errors when that header defines multiple overloaded versions of a function.

This problem only occurs on solaris, with gcc 3.x. Everything works fine on linux, or with solaris and gcc 2.95.

If the header file can be found on standard system paths, or  is in the current directory, or its directory is specified explicitly with a -I flag to the compiler, then everything works fine. The problem only happens when the header is found via CPLUS_INCLUDE_PATH.

The example given below uses these two files:

foo.h:
-----------------------------------------
// Dummy overloaded prototypes

void foo(int x);
void foo(double x);
-----------------------------------------


and foo.cc:
-----------------------------------------
#include "foo.h"

int main() {
  main();
}
-----------------------------------------

Simply compiling foo.cc causes errors on gcc 3.x on solaris, if foo.h is found via the CPLUS_INCLUDE_PATH.

This PR seems similar to 4662, but there was no resolution to that one that I could see. A search on the web seems to turn up a number of people reporting similar problems in other places.

Release:
gcc-3.0.3

Environment:
sparc-sun-solaris2.8

How-To-Repeat:
Using bash:

cerrogrande[tmp] tar xvf foo.tar
foo/
foo/bar/
foo/bar/foo.cc
foo/foo.h
cerrogrande[tmp] cd foo/bar
cerrogrande[bar] export CPLUS_INCLUDE_PATH=..
cerrogrande[bar] g++ foo.cc -c
In file included from foo.cc:1:
../foo.h:4: declaration of C function `void foo(double)' conflicts with
../foo.h:3: previous declaration `void foo(int)' here
cerrogrande[bar] 



Or in more detail:

cerrogrande[bar] g++ foo.cc -c -v
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/specs
Configured with: ../configure --with-as=/usr/local/bin/as --with-ld=/usr/local/bin/ld --enable-libgcj
Thread model: posix
gcc version 3.0.3
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=3 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem=unix -Asystem=svr4 -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_XOPEN_SOURCE=500 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -D__EXTENSIONS__ -D__GCC_NEW_VARARGS__ -Acpu=sparc -Amachine=sparc foo.cc -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase foo.cc -version -o /var/tmp/ccutpIcL.s
GNU CPP version 3.0.3 (cpplib) (sparc)
GNU C++ version 3.0.3 (sparc-sun-solaris2.8)
        compiled by GNU C version 3.0.3.
ignoring nonexistent directory "/usr/local/sparc-sun-solaris2.8/include"
#include "..." search starts here:
#include <...> search starts here:
 ..
 /usr/local/include/g++-v3
 /usr/local/include/g++-v3/sparc-sun-solaris2.8
 /usr/local/include/g++-v3/backward
 /usr/local/include
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.0.3/include
 /usr/include
End of search list.
In file included from foo.cc:1:
../foo.h:4: declaration of C function `void foo(double)' conflicts with
../foo.h:3: previous declaration `void foo(int)' here
cerrogrande[bar] 


But on the other hand:

cerrogrande[bar] g++ foo.cc -c -I..
cerrogrande[bar] 

works fine...
Comment 1 s.perkins 2002-08-14 19:56:01 UTC
Fix:
Switch to using linux... :)
Comment 2 Neil Booth 2002-08-15 08:02:11 UTC
From: Neil Booth <neil@daikokuya.co.uk>
To: s.perkins@lanl.gov
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/7602: C++ header files found in CPLUS_INCLUDE_PATH treated as C headers
Date: Thu, 15 Aug 2002 08:02:11 +0100

 s.perkins@lanl.gov wrote:-
 
 > The example given below uses these two files:
 > 
 > foo.h:
 > -----------------------------------------
 > // Dummy overloaded prototypes
 > 
 > void foo(int x);
 > void foo(double x);
 > -----------------------------------------
 > 
 > 
 > and foo.cc:
 > -----------------------------------------
 > #include "foo.h"
 > 
 > int main() {
 >   main();
 > }
 > -----------------------------------------
 
 Hi,
 
 If I have foo.C in /tmp, foo.h in /tmp/foo and do the following on
 Linux:
 
 CPLUS_INCLUDE_PATH=/tmp/foo g++ /tmp/foo.C -E
 
 I get:
 
 # 1 "/tmp/foo.C"
 # 1 "<built-in>"
 # 1 "<command line>"
 # 1 "/tmp/foo.C"
 # 1 "/tmp/foo/foo.h" 1 3 4
 void foo(int x);
 void foo(double x);
 # 2 "/tmp/foo.C" 2
 
 int main() {
   main();
   }
 
 Can you please tell me what you get on Solaris, and which version
 of GCC it is.
 
 Neil.

Comment 3 Neil Booth 2002-08-18 02:51:29 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Fixed in 3.2.1.
Comment 4 Neil Booth 2002-08-18 06:24:14 UTC
From: neil@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: preprocessor/7602
Date: 18 Aug 2002 06:24:14 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	neil@gcc.gnu.org	2002-08-17 23:24:14
 
 Modified files:
 	gcc            : ChangeLog cppinit.c 
 
 Log message:
 	PR preprocessor/7602
 	* cppinit.c (path_include): Treat the system environment
 	variables as being cxx_aware.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.14&r2=1.13152.2.657.2.15
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cppinit.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.202.2.5.2.1&r2=1.202.2.5.2.2
 

Comment 5 Neil Booth 2002-08-18 06:26:11 UTC
From: neil@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: preprocessor/7602
Date: 18 Aug 2002 06:26:11 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	neil@gcc.gnu.org	2002-08-17 23:26:11
 
 Modified files:
 	gcc            : ChangeLog cppinit.c 
 
 Log message:
 	PR preprocessor/7602
 	* cppinit.c (path_include): Treat the system environment
 	variables as being cxx_aware.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.15206&r2=1.15207
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cppinit.c.diff?cvsroot=gcc&r1=1.257&r2=1.258