This is the mail archive of the gcc@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]

Re: Redeclaration of used symbols


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)

> If so, what should be semantic in function-at-a-time compilation?
> If not, what is the best way to error about it? (check in
> duplicate_decls whether entity has an initializer or is used comes
> into mind)

You could simply remove the special case code in duplicate_decls that
lets this go through.  I am in favor of making it a hard error even in
non-unit-at-a-time mode -- I don't think the validity of code should
depend on whether or not the translation unit is being analyzed in
toto.

zw


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