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.
This commit is contained in:
@@ -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
|
||||
#error "Need to define compiler options in base/compiler.hh"
|
||||
# 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
|
||||
# define M5_CLASS_VAR_USED
|
||||
#endif
|
||||
|
||||
#endif // __BASE_COMPILER_HH__
|
||||
|
||||
Reference in New Issue
Block a user