Skip to contentSkip to conversation

build: Don't redefine 'inline'

PATCH Applied Eric Blake 2 participants 4 messages Feb 9, 2016 – Feb 16, 2016

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

PATCH 1/1 build: Don't redefine 'inline'

Actively redefining 'inline' is wrong for C++, where gcc has an extension 'inline namespace' which fails to compile if the keyword 'inline' is replaced by a macro expansion. This will matter once we start to include "qemu/osdep.h" first from C++ files, depending also on whether the system headers are new enough to be using the gcc extension.

But rather than just guard things by __cplusplus, let's look at the overall picture. Commit df2542c737ea2 in 2007 defined 'inline' to the gcc attribute __always_inline__, with the rationale "To avoid discarded inlining bug". But compilers have improved since then, and we are probably better off trusting the compiler rather than trying to force its hand.

So just nuke our craziness.

---
 include/qemu/compiler.h | 12 ------------
 1 file changed, 12 deletions(-)
include/qemu/compiler.h +0 -12
index d22eb01..c5fbe28 100644
@@ -77,18 +77,6 @@
 #define typeof_field(type, field) typeof(((type *)0)->field)
 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
 
-#ifndef always_inline
-#if !((__GNUC__ < 3) || defined(__APPLE__))
-#ifdef __OPTIMIZE__
-#undef inline
-#define inline __attribute__ (( always_inline )) __inline__
-#endif
-#endif
-#else
-#undef inline
-#define inline always_inline
-#endif
-
 #define QEMU_BUILD_BUG_ON(x) \
     typedef char glue(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused));
 
Signature · 1 line
2.5.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Eric Blake

Actively redefining 'inline' is wrong for C++, where gcc has an extension 'inline namespace' which fails to compile if the keyword 'inline' is replaced by a macro expansion. This will matter once we start to include "qemu/osdep.h" first from C++ files, depending also on whether the system headers are new enough to be using the gcc extension.

But rather than just guard things by __cplusplus, let's look at the overall picture. Commit df2542c737ea2 in 2007 defined 'inline' to the gcc attribute __always_inline__, with the rationale "To avoid discarded inlining bug". But compilers have improved since then, and we are probably better off trusting the compiler rather than trying to force its hand.

Quoted 3 lines

So just nuke our craziness.

(and tested that it passes my usual merge build tests).

Does this patch suffice to get your system to build all my clean-includes patches?

thanks
-- PMM

author
#2 lore raw
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Eric Blake

Actively redefining 'inline' is wrong for C++, where gcc has an extension 'inline namespace' which fails to compile if the keyword 'inline' is replaced by a macro expansion. This will matter once we start to include "qemu/osdep.h" first from C++ files, depending also on whether the system headers are new enough to be using the gcc extension.

But rather than just guard things by __cplusplus, let's look at the overall picture. Commit df2542c737ea2 in 2007 defined 'inline' to the gcc attribute __always_inline__, with the rationale "To avoid discarded inlining bug". But compilers have improved since then, and we are probably better off trusting the compiler rather than trying to force its hand.

So just nuke our craziness.

Quoted 8 lines
Quoted 1 line

(and tested that it passes my usual merge build tests).

Does this patch suffice to get your system to build all my clean-includes patches?

Yes.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw
In reply to Eric Blake
Quoted 14 lines · Eric Blake

Actively redefining 'inline' is wrong for C++, where gcc has an extension 'inline namespace' which fails to compile if the keyword 'inline' is replaced by a macro expansion. This will matter once we start to include "qemu/osdep.h" first from C++ files, depending also on whether the system headers are new enough to be using the gcc extension.

But rather than just guard things by __cplusplus, let's look at the overall picture. Commit df2542c737ea2 in 2007 defined 'inline' to the gcc attribute __always_inline__, with the rationale "To avoid discarded inlining bug". But compilers have improved since then, and we are probably better off trusting the compiler rather than trying to force its hand.

Quoted 6 lines

So just nuke our craziness.

---
 include/qemu/compiler.h | 12 ------------
 1 file changed, 12 deletions(-)

Applied to master, thanks. I am all in favour of reducing the craziness quotient of our codebase.

-- PMM