This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Redeclaration of used symbols
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: "Zack Weinberg" <zack at codesourcery dot com>
- Cc: Jan Hubicka <hubicka at ucw dot cz>, gcc at gcc dot gnu dot org, schwab at suse dot de, rth at redhat dot com
- Date: 07 Sep 2003 19:21:31 +0200
- Subject: Re: Redeclaration of used symbols
- Organization: Integrable Solutions
- References: <20030907135208.GC14387@kam.mff.cuni.cz><87he3oy1s7.fsf@egil.codesourcery.com>
"Zack Weinberg" <zack@codesourcery.com> writes:
| Jan Hubicka <hubicka@ucw.cz> writes:
|
| > Hi,
| > We currently accept the following testcase:
| >
| > t()
| > {
| > }
| > static int t();
| > b()
| > {
| > t();
| > }
| >
| > when compiled with -fPIC we get an global symbol t that is called as if
| > it were local symbol in non-PIC way on i386. I believe we get similar
| > misscompilations on most of other targets as well as confussion of the
| > unit-at-a-time code and such.
| >
| > Is this valid C?
|
| No, it's undefined behavior - t is declared in the same scope with two
| different linkages. (6.2.2p7)
That is to be contrasted with:
6.2.2/4
[#4] For an identifier declared with the storage-class
specifier extern in a scope in which a prior declaration of
that identifier is visible,23) if the prior declaration
specifies internal or external linkage, the linkage of the
identifier at the later declaration is the same as the
linkage specified at the prior declaration. If no prior
declaration is visible, or if the prior declaration
specifies no linkage, then the identifier has external
linkage.
thus an identifier can be declared "static" or "extern" and later
redeclared "extern", the first linkage declaration wins.
But I agree that the other way around is undefined behaviour as per
6.2.2/7. It can be diagnosed and I too will suggest a hard error.