public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26271]  New: strange behavior with no warning at -Wall when redeclaring static function extern
@ 2006-02-14  0:07 josh dot parsons at stonebow dot otago dot ac dot nz
  2006-02-14  0:17 ` [Bug c/26271] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: josh dot parsons at stonebow dot otago dot ac dot nz @ 2006-02-14  0:07 UTC (permalink / raw)
  To: gcc-bugs

Because of a mistaken preprocessor macro I ended up compiling a program like
this:

static void foo() {};

void *bar() {
  extern void foo();
  return foo;
}

int main() {
  return bar()==foo;
}

Of course this was not what I intended to do (I don't even know whether it's
legal C) but gcc 3.4.4 compiled and linked it with no warnings (even given
-Wall).  Now, here's the weird thing: it seems that, when compiling with -m32
or without -fPIC, bar() returns the address of the static function foo()!
However, when compiling with -m64 and -fPIC, bar() returns some seemingly
random value. In neither case is there any compiler or linker warning.

What should happen instead is surely one of the following:

1) gcc should emit a warning or error about redeclaring foo() from static to
extern linkage, or...

2) gcc should emit a warning about the undefined behavior of taking the address
of foo() in the context of bar(), or...

3) gcc should consistently generate code for bar() to get the address of some
global symbol "foo", not the static function foo() (in the case of the program
above, ultimately causing a linker error).


-- 
           Summary: strange behavior with no warning at -Wall when
                    redeclaring static function extern
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: josh dot parsons at stonebow dot otago dot ac dot nz
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26271


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/26271] strange behavior with no warning at -Wall when redeclaring static function extern
  2006-02-14  0:07 [Bug c/26271] New: strange behavior with no warning at -Wall when redeclaring static function extern josh dot parsons at stonebow dot otago dot ac dot nz
@ 2006-02-14  0:17 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-14  0:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-14 00:17 -------
This is valid code besides the extra semicolon and converting between between
function pointer types and void*.

This is a dup of bug 24097.

*** This bug has been marked as a duplicate of 24097 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26271


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-02-14  0:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-14  0:07 [Bug c/26271] New: strange behavior with no warning at -Wall when redeclaring static function extern josh dot parsons at stonebow dot otago dot ac dot nz
2006-02-14  0:17 ` [Bug c/26271] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).