changeset 56772eb01583 in /z/repo/gem5 details: http://repo.gem5.org/gem5?cmd=changeset;node=56772eb01583 description: 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. diffstat: src/base/compiler.hh | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 38 insertions(+), 12 deletions(-) diffs (65 lines): diff -r b7715fb7cf9f -r 56772eb01583 src/base/compiler.hh --- a/src/base/compiler.hh Tue Aug 26 10:13:31 2014 -0400 +++ b/src/base/compiler.hh Tue Aug 26 10:13:33 2014 -0400 @@ -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) + +#else +# error "Need to define compiler options in base/compiler.hh" +#endif + + +#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 +# define M5_CLASS_VAR_USED M5_VAR_USED #else -#define M5_CLASS_VAR_USED -#endif - -#define M5_ATTR_PACKED __attribute__ ((__packed__)) -#define M5_NO_INLINE __attribute__ ((__noinline__)) -#else -#error "Need to define compiler options in base/compiler.hh" +# define M5_CLASS_VAR_USED #endif #endif // __BASE_COMPILER_HH__ _______________________________________________ gem5-dev mailing list gem5-dev@gem5.org http://m5sim.org/mailman/listinfo/gem5-dev