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

[Bug c++/15720] New: function marked inline which is called directly isn't emitted


In a class, an constructor marked as inline calls an function marked as inline.  When compiled with top-
of-tree on Darwin with g++, the code fails to link because the compiler failed to emit the function.  If 
the function's declaration in the class is specified as inline, then the function is produced as expected.

To reproduce, make the attached project.

Here's the output with 3.5 at the tree-ssa-pre-merge tag:

[bowdro2:~/Tests/Missing] bowdidge% make CXX=/Volumes/Compilers/gccInstalls/gcc.FSF.tree-ssa-
pre-merge/bin/g++
/Volumes/Compilers/gccInstalls/gcc.FSF.tree-ssa-pre-merge/bin/g++    -c -o a.o a.cpp
a.cpp: In function `int main()':
a.cpp:3: warning: address of local variable `foo' returned

Here's the output with current top-of-tree:

[bowdro2:~/Tests/Missing] bowdidge% make CXX=/Volumes/Compilers/gccInstalls/gcc.FSF.TOT/bin/
g++
/Volumes/Compilers/gccInstalls/gcc.FSF.TOT/bin/g++    -c -o a.o a.cpp
a.cpp: In function `int main()':
a.cpp:3: warning: address of local variable `foo' returned
/Volumes/Compilers/gccInstalls/gcc.FSF.TOT/bin/g++    -c -o b.o b.cpp
/Volumes/Compilers/gccInstalls/gcc.FSF.TOT/bin/g++ -o a a.o b.o
/usr/bin/ld: Undefined symbols:
QMacSavedFontInfo::init(int)
collect2: ld returned 1 exit status

If the object files are examined, the difference causing the problem is (
>          U __ZN17QMacSavedFontInfo4initEi
6c5
< 0000010c S __ZN17QMacSavedFontInfoC1Ev.eh
---
> 000000cc S __ZN17QMacSavedFontInfoC1Ev.eh

Here are the four needed files: Makefile, a.cpp, b.h, b.cpp

Makefile:

CFLAGS= -g

a: a.o b.o
        $(CXX) -o a a.o b.o

clean:
        \rm -f a a.o b.o

a.cpp:
#include "b.h"
main () {
  QMacSavedFontInfo foo;
  return (int) &foo;
}


b.h:
typedef int CGrafPtr;
typedef int GWorldPtr;
typedef int GDHandle;
extern void GetGWorld(int*,int*);

class QMacSavedFontInfo
{
private:
        /* Adding inline here solves the problem. */
   void init(CGrafPtr);
protected:
    short tfont, tface;
    int tsize;
public:
    QMacSavedFontInfo() { GWorldPtr w; GDHandle h; GetGWorld(&w, &h); init(w); }
};

/* Not declaring this inline makes the problem go away. */
inline
  void QMacSavedFontInfo::init(CGrafPtr w)
{
 tfont = 1;
 tface = 1;
 tsize = 1;
}

b.cpp:
#include "b.h"

extern void GetGWorld(int*,int*) {
}

-- 
           Summary: function marked inline which is called directly isn't
                    emitted
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bowdidge at apple dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-apple-darwin7.4.0
  GCC host triplet: powerpc-apple-darwin7.4.0
GCC target triplet: powerpc-apple-darwin7.4.0


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


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