diff options
author | Andreas Sandberg <Andreas.Sandberg@ARM.com> | 2014-08-26 10:13:33 -0400 |
---|---|---|
committer | Andreas Sandberg <Andreas.Sandberg@ARM.com> | 2014-08-26 10:13:33 -0400 |
commit | f3e5fee74373d16849a58a80827c54c773aa05e2 (patch) | |
tree | 7ea75e15a82a36ccf3e5e95c791ca1dea9b27284 | |
parent | 0da99b7e0c40d924c8555ef41c38d361ea6c626d (diff) | |
download | gem5-f3e5fee74373d16849a58a80827c54c773aa05e2.tar.xz |
base: Add compiler macros for C++11 final/override
Add the macros M5_ATTR_FINAL and M5_ATTR_OVERRIDE which are defined to
final and override respectively if supported by the compiler. This is
done to allow a smooth transition to gcc >= 4.7.
-rw-r--r-- | src/base/compiler.hh | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/base/compiler.hh b/src/base/compiler.hh index 0e3c85a78..b1fea055c 100644 --- a/src/base/compiler.hh +++ b/src/base/compiler.hh @@ -43,23 +43,49 @@ #ifndef __BASE_COMPILER_HH__ #define __BASE_COMPILER_HH__ +// gcc C++11 status: http://gcc.gnu.org/projects/cxx0x.html +// clang C++11 status: http://clang.llvm.org/cxx_status.html // http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html -#if defined(__GNUC__) -#define M5_ATTR_NORETURN __attribute__((noreturn)) -#define M5_DUMMY_RETURN -#define M5_VAR_USED __attribute__((unused)) +/* Support for override control (final/override) */ +#undef M5_COMP_HAS_OVERRIDE_CONTROL + +#if defined(__GNUC__) && !defined(__clang__) /* Check for gcc */ + +# define M5_GCC_VERSION(maj, min) \ + (__GNUC__ > (maj) || (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min))) + +# define M5_COMP_HAS_OVERRIDE_CONTROL M5_GCC_VERSION(4, 7) + +#elif defined(__clang__) /* Check for clang */ + +# define M5_COMP_HAS_OVERRIDE_CONTROL __has_feature(cxx_override_control) -#if defined(__clang__) -#define M5_CLASS_VAR_USED M5_VAR_USED #else -#define M5_CLASS_VAR_USED +# error "Need to define compiler options in base/compiler.hh" #endif -#define M5_ATTR_PACKED __attribute__ ((__packed__)) -#define M5_NO_INLINE __attribute__ ((__noinline__)) + +#if M5_COMP_HAS_OVERRIDE_CONTROL +# define M5_ATTR_FINAL final +# define M5_ATTR_OVERRIDE override +#else +# define M5_ATTR_FINAL +# define M5_ATTR_OVERRIDE +#endif + +#if defined(__GNUC__) // clang or gcc +# define M5_ATTR_NORETURN __attribute__((noreturn)) +# define M5_DUMMY_RETURN +# define M5_VAR_USED __attribute__((unused)) +# define M5_ATTR_PACKED __attribute__ ((__packed__)) +# define M5_NO_INLINE __attribute__ ((__noinline__)) +#endif + +#if defined(__clang__) +# define M5_CLASS_VAR_USED M5_VAR_USED #else -#error "Need to define compiler options in base/compiler.hh" +# define M5_CLASS_VAR_USED #endif #endif // __BASE_COMPILER_HH__ |