Bug 751554 part 1 - Support explicit underlying enum types in MFBT; r=cjones

This commit is contained in:
Aryeh Gregor 2012-08-05 12:11:24 +03:00
parent 3e75cf3f4a
commit f0251cc7b5

View File

@ -70,6 +70,9 @@
# define MOZ_HAVE_CXX11_OVERRIDE
# define MOZ_HAVE_CXX11_FINAL final
# endif
# if __has_extension(cxx_strong_enums)
# define MOZ_HAVE_CXX11_ENUM_TYPE
# endif
# if __has_attribute(noinline)
# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline))
# endif
@ -89,6 +92,7 @@
# endif
# if __GNUC_MINOR__ >= 4
# define MOZ_HAVE_CXX11_DELETE
# define MOZ_HAVE_CXX11_ENUM_TYPE
# endif
# endif
# else
@ -108,6 +112,7 @@
# define MOZ_HAVE_CXX11_OVERRIDE
/* MSVC currently spells "final" as "sealed". */
# define MOZ_HAVE_CXX11_FINAL sealed
# define MOZ_HAVE_CXX11_ENUM_TYPE
# endif
# define MOZ_HAVE_NEVER_INLINE __declspec(noinline)
# define MOZ_HAVE_NORETURN __declspec(noreturn)
@ -298,6 +303,31 @@
# define MOZ_FINAL /* no support */
#endif
/**
* MOZ_ENUM_TYPE specifies the underlying numeric type for an enum. It's
* specified by placing MOZ_ENUM_TYPE(type) immediately after the enum name in
* its declaration, and before the opening curly brace, like
*
* enum MyEnum MOZ_ENUM_TYPE(PRUint16)
* {
* A,
* B = 7,
* C
* };
*
* In supporting compilers, the macro will expand to ": PRUint16". The
* compiler will allocate exactly two bytes for MyEnum, and will require all
* enumerators to have values between 0 and 65535. (Thus specifying "B =
* 100000" instead of "B = 7" would fail to compile.) In old compilers, the
* macro expands to the empty string, and the underlying type is generally
* undefined.
*/
#ifdef MOZ_HAVE_CXX11_ENUM_TYPE
# define MOZ_ENUM_TYPE(type) : type
#else
# define MOZ_ENUM_TYPE(type) /* no support */
#endif
/**
* MOZ_WARN_UNUSED_RESULT tells the compiler to emit a warning if a function's
* return value is not used by the caller.