public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46589] New: struct member function not declared global
@ 2010-11-21 13:21 temptony at freemail dot hu
  2010-11-21 18:04 ` [Bug c++/46589] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: temptony at freemail dot hu @ 2010-11-21 13:21 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: struct member function not declared global
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: temptony@freemail.hu


Summary of bug:

g++ doesn't declare L::G() global in the following code:
  typedef struct { void G() ; } L ;
  void L::G() { }

although it does here ('typedef struct L' instead of 'typedef struct'):
  typedef struct L { void G() ; } L ;
  void L::G() { }

Output from gcc -v:

  Using built-in specs.
  Target: mingw32
  Configured with: ../gcc-4.4.0/configure
--enable-languages=c,ada,c++,fortran,java,objc,obj-c++ --dis
  able-sjlj-exceptions --enable-shared --enable-libgcj --enable-libgomp
--with-dwarf2 --disable-win32-
  registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs
--prefix=/mingw --with-gmp=
  /mingw/src/gmp/root --with-mpfr=/mingw/src/mpfr/root --build=mingw32
  Thread model: win32
  gcc version 4.4.0 (GCC)

File main.cpp:

  typedef struct { void G() ; } L ;
  static L X ;
  int main() { X.G() ; }

File L0.cpp:

  typedef struct { void G() ; } L ;
  void L::G() { }

The command:

  g++ main.cpp L0.cpp

This fails with:

  C:\...\Temp\ccCl8AUu.o:main.cpp:(.text+0x16): undefined reference to `L::G()'
  collect2: ld returned 1 exit status

BUT: File L1.cpp has 'typedef struct' instead of 'typedef struct L':

  typedef struct L { void G() ; } L ;
  void L::G() { }

  g++ main.cpp L1.cpp

This works!

The difference can be seen in the assembly output:

    .file    "L0.cpp"
    .text
    .align 2
    .def    __ZN1L1GEv;    .scl    3;    .type    32;    .endef
__ZN1L1GEv:
LFB0:
    pushl    %ebp
LCFI0:
    movl    %esp, %ebp
LCFI1:
    leave
    ret
LFE0:

    .file    "L1.cpp"
    .text
    .align 2
.globl __ZN1L1GEv
    .def    __ZN1L1GEv;    .scl    2;    .type    32;    .endef
__ZN1L1GEv:
LFB0:
    pushl    %ebp
LCFI0:
    movl    %esp, %ebp
LCFI1:
    leave
    ret
LFE0:

__ZN1L1GEv is not declared global in L0.s.


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

end of thread, other threads:[~2021-08-05 11:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-21 13:21 [Bug c++/46589] New: struct member function not declared global temptony at freemail dot hu
2010-11-21 18:04 ` [Bug c++/46589] " redi at gcc dot gnu.org
2010-11-21 22:42 ` paolo.carlini at oracle dot com
2010-11-21 23:17 ` redi at gcc dot gnu.org
2010-11-22  1:39 ` temptony at freemail dot hu
2010-11-22  3:48 ` paolo.carlini at oracle dot com
2010-11-22  8:50 ` redi at gcc dot gnu.org
2011-01-02 14:29 ` ktietz at gcc dot gnu.org
2011-01-02 17:23 ` hjl.tools at gmail dot com
2021-08-05 11:33 ` redi at gcc dot gnu.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).