Bug 11285 - GCC 3.3 C++ for Sparc Solaris assumes system header files are C.
Summary: GCC 3.3 C++ for Sparc Solaris assumes system header files are C.
Status: RESOLVED DUPLICATE of bug 7327
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 1773
Blocks:
  Show dependency treegraph
 
Reported: 2003-06-22 17:07 UTC by Michael Frame
Modified: 2003-08-29 22:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-06-22 23:25:46


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Frame 2003-06-22 17:07:08 UTC
I noticed this problem first with GCC 3.2.3, upgraded to the latest build I
could get to compile (3.3), and it still exists. It only seems to appear on
Sparc Solaris, I could not reproduce it on any other platform, including Sparc
Linux.

Essentially, it appears any header file included as "#include <header>" is
assumed to be C, even when included in C++ (.cc, .C, .cpp all tested) code. This
causes errors if function overloading is used.

I reproduced the problem with a very simple test, one header file in
/usr/include containing an overloaded function definition, and a C++ main that
only includes the header and returns 1. The .ii file looks correct, but on
compile it complains that declaration of C function `int test(int, int)'
conflicts with `int test(int)'.

Your bug reporting guidelines specify to include the preprocessed .ii file, but
I don't see any method of attaching a file here. If one would be helpful, please
feel free to e-mail me.
Comment 1 Wolfgang Bangerth 2003-06-22 18:17:31 UTC
System headers really _are_ usually C, not C++. On many systems,
they are therefore wrapped into
  extern "C" {
    ...
  }
blocks if C++ is used. Can you check whether that is the case on
your system as well?

Wolfgang
Comment 2 Michael Frame 2003-06-22 23:05:23 UTC
The real system headers mostly are, yes, the ones I'm creating for my own
development aren't. And those are the ones with problems.

As I mentioned earlier, I reproduced the problem with a very simple set of
files. The contents of the two simple files are as below.

/usr/include/test.h
------------------------
int test (int a);
int test (int a, int b);
------------------------

test.cpp
------------------
#include <test.h>
int main(void) {
	return 1;
}
------------------


Also of note, when I put the file in the current directory and include it with
'#include "test.h"' it compiles fine.
Comment 3 Andrew Pinski 2003-06-22 23:25:46 UTC
the config file of solaris does not define NO_IMPLICIT_EXTERN_C which says the header files in the 
system path is c++ aware.  I think this is a feature until Sun (your provider) releases a system with 
c++ aware headers.  I do not know when that is, you have to ask them.
Comment 4 Michael Frame 2003-06-22 23:33:31 UTC
Perhaps I am misunderstanding what you said, but they look fairly C++ aware to
me...here's a clip from the top of stdio.h...

I'm using Solaris 9, perhaps they implemented that with this version?
In which file could I find that value to change? I can test it here.

---------------------------------------------------------------------
<snip>
/*
 * Copyright (c) 1993-2001, by Sun Microsystems, Inc.
 * All rights reserved.
 */
<snip>
/*
 * Allow global visibility for symbols defined in
 * C++ "std" namespace in <iso/stdio_iso.h>.
 */
#if __cplusplus >= 199711L
using std::FILE;
using std::size_t;
using std::fpos_t;
<snip>
using std::perror;
#endif
                                                                                
#ifdef  __cplusplus
extern "C" {
#endif
<etc, etc...>
Comment 5 Andrew Pinski 2003-06-22 23:36:38 UTC
Then it looks like this can be fix for 2.9 (aka Solaris 9) only.  Then the feature needs to be disabled 
on Solaris 9.
Comment 6 Gabriel Dos Reis 2003-06-23 07:45:10 UTC
Subject: Re:  GCC 3.3 C++ for Sparc Solaris assumes system header files are C.

"numien at deathwyrm dot net" <gcc-bugzilla@gcc.gnu.org> writes:

| Perhaps I am misunderstanding what you said, but they look fairly C++ aware to
| me...here's a clip from the top of stdio.h...

Indeed.

| I'm using Solaris 9, perhaps they implemented that with this version?
| In which file could I find that value to change? I can test it here.
| 
| ---------------------------------------------------------------------
| <snip>
| /*
|  * Copyright (c) 1993-2001, by Sun Microsystems, Inc.
|  * All rights reserved.
|  */
| <snip>
| /*
|  * Allow global visibility for symbols defined in
|  * C++ "std" namespace in <iso/stdio_iso.h>.
|  */
| #if __cplusplus >= 199711L

Aha, I get it.  Currently g++ (or libstdc++-v3 I can tell which)
defines __cplusplus to 1L because we don't know how to handle Sun's C
system headers which are already C++ aware.  The point is:  In this
specific case, it is not that Sun's are not C++ aware, the problem is
that they *are*, but we don't know how to build libstdc++-v3 with such
systems. Put differently, it is our fault.  The fix is not obbious though.
There should be an open issue related to __cplusplus somewhere in the
archive. 

-- gaby
Comment 7 Gabriel Dos Reis 2003-06-23 07:45:14 UTC
Subject: Re:  GCC 3.3 C++ for Sparc Solaris assumes system header files are C.

"pinskia at physics dot uc dot edu" <gcc-bugzilla@gcc.gnu.org> writes:

| Then it looks like this can be fix for 2.9 (aka Solaris 9) only.  Then the feature needs to be disabled 
| on Solaris 9.

See past discussion on an issue related to __cplucplus.

-- Gaby
Comment 8 Michael Frame 2003-07-29 18:50:10 UTC
Took a bit of time to test and get back here (mostly due to problems with time
and Suns, gotta love 'em sometimes) but Andrew Pinski's solution seems to work
perfectly. Thanks.
Comment 9 Jason Merrill 2003-08-29 22:35:24 UTC

*** This bug has been marked as a duplicate of 7327 ***
Comment 10 GCC Commits 2005-04-27 21:03:11 UTC
Subject: Bug 11285

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mkoch@gcc.gnu.org	2005-04-27 21:03:00

Modified files:
	libjava        : ChangeLog 
	libjava/gnu/java/net/protocol/file: Connection.java 
	libjava/java/net: URLClassLoader.java 

Log message:
	2005-04-27  Chris Burdess  <dog@gnu.org>
	
	* gnu/java/net/protocol/file/Connection.java: Return correct content
	length for directory listing.
	* java/net/URLClassLoader.java: Correction for URLClassLoader, bug
	#11285: return valid URLs for directories.i

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3568&r2=1.3569
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/gnu/java/net/protocol/file/Connection.java.diff?cvsroot=gcc&r1=1.10&r2=1.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/net/URLClassLoader.java.diff?cvsroot=gcc&r1=1.28&r2=1.29