In the code below, g++ should eliminate both function calls when called with
-O2:
$ cat > inline_varargs.c <<END
inline void nonVararg( const char * dummy ) {}
inline void Vararg( const char * dummy, ... ) {}
int main()
{
nonVararg("Hello");
Vararg("World");
}
END
$ g++ -O2 inline_varargs.c
$ objdump -d a.out | c++filt | grep Vararg
8048408: e8 13 00 00 00 call 8048420 <Vararg(char const*,
...)>
08048420 <Vararg(char const*, ...)>:
$ gcc -O2 inline_varargs.c
$ objdump -d a.out | grep Vararg
08048350 <nonVararg>:
08048360 <Vararg>:
$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2
--program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --disable-libmudflap --enable-targets=all
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.2.4 20080512 (prerelease) (Debian 4.2.3-6)
As can be seen, gcc correclty inlines both functions, while g++ does not inline
the varargs function.
Trying to force inlining with __attribute__((always_inline)) leads to the
following error message:
inline_varargs.c: In function ‘int main()’:
inline_varargs.c:3: sorry, unimplemented: inlining failed in call to
‘void Vararg(const char*, ...)’: function not inlinable
inline_varargs.c:7: sorry, unimplemented: called from here
This might be related to bug 10980, but as it works with gcc, I'm not sure what
the problem really is.
--
Summary: g++ doesn't inline vararg functions
Product: gcc
Version: 4.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: thomas dot bleher at philosys dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39140