Fix build on MSVC >= 2012

Use the DEFINE_ENUM_FLAG_OPERATORS macro in winnt.h on Visual Studio,
which defines the bitwise operators for the enumerations that we want to
mark as hb_mark_as_flags_t, which will take care of the situation on newer
Visual Studio (>= 2012), where the build breaks with C2057 errors as the
underlying types of the enumerations is not clear to the compiler when we
do a bitwise op within the declaration of the enumerations themselves.

Also disable the C4200 (nonstandard extension used : zero-sized array in
struct/union) and C4800 ('type' : forcing value to bool 'true' or 'false'
(performance warning)) warnings as the C4200 is the intended scenario and
C4800 is harmless but is so far an unavoidable side effect of using
DEFINE_ENUM_FLAG_OPERATORS.
This commit is contained in:
Chun-wei Fan 2015-11-09 17:17:56 +08:00
parent 4d27bb8746
commit 167c327177
5 changed files with 18 additions and 7 deletions

View File

@ -48,8 +48,8 @@
ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20); ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20);
ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)); ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t));
template <> class hb_mark_as_flags_t<hb_buffer_flags_t> {}; HB_MARK_AS_FLAG_T (hb_buffer_flags_t);
template <> class hb_mark_as_flags_t<hb_buffer_serialize_flags_t> {}; HB_MARK_AS_FLAG_T (hb_buffer_serialize_flags_t);
enum hb_buffer_scratch_flags_t { enum hb_buffer_scratch_flags_t {
HB_BUFFER_SCRATCH_FLAG_DEFAULT = 0x00000000u, HB_BUFFER_SCRATCH_FLAG_DEFAULT = 0x00000000u,
@ -64,7 +64,7 @@ enum hb_buffer_scratch_flags_t {
HB_BUFFER_SCRATCH_FLAG_COMPLEX2 = 0x04000000u, HB_BUFFER_SCRATCH_FLAG_COMPLEX2 = 0x04000000u,
HB_BUFFER_SCRATCH_FLAG_COMPLEX3 = 0x08000000u, HB_BUFFER_SCRATCH_FLAG_COMPLEX3 = 0x08000000u,
}; };
template <> class hb_mark_as_flags_t<hb_buffer_scratch_flags_t> {}; HB_MARK_AS_FLAG_T (hb_buffer_scratch_flags_t);
/* /*

View File

@ -581,7 +581,7 @@ struct LookupFlag : USHORT
} /* namespace OT */ } /* namespace OT */
/* This has to be outside the namespace. */ /* This has to be outside the namespace. */
template <> class hb_mark_as_flags_t<OT::LookupFlag::Flags> {}; HB_MARK_AS_FLAG_T (OT::LookupFlag::Flags);
namespace OT { namespace OT {
struct Lookup struct Lookup

View File

@ -65,7 +65,7 @@ enum hb_ot_layout_glyph_props_flags_t
HB_OT_LAYOUT_GLYPH_PROPS_LIGATED | HB_OT_LAYOUT_GLYPH_PROPS_LIGATED |
HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED
}; };
template <> class hb_mark_as_flags_t<hb_ot_layout_glyph_props_flags_t> {}; HB_MARK_AS_FLAG_T (hb_ot_layout_glyph_props_flags_t);
/* /*
@ -237,7 +237,7 @@ enum hb_unicode_props_flags_t {
UPROPS_MASK_IGNORABLE = 0x80u, UPROPS_MASK_IGNORABLE = 0x80u,
UPROPS_MASK_GEN_CAT = 0x1Fu UPROPS_MASK_GEN_CAT = 0x1Fu
}; };
template <> class hb_mark_as_flags_t<hb_unicode_props_flags_t> {}; HB_MARK_AS_FLAG_T (hb_unicode_props_flags_t);
static inline void static inline void
_hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_buffer_t *buffer) _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_buffer_t *buffer)

View File

@ -159,7 +159,7 @@ enum hb_ot_map_feature_flags_t {
F_MANUAL_ZWJ = 0x0004u, /* Don't skip over ZWJ when matching. */ F_MANUAL_ZWJ = 0x0004u, /* Don't skip over ZWJ when matching. */
F_GLOBAL_SEARCH = 0x0008u /* If feature not found in LangSys, look for it in global feature list and pick one. */ F_GLOBAL_SEARCH = 0x0008u /* If feature not found in LangSys, look for it in global feature list and pick one. */
}; };
template <> class hb_mark_as_flags_t<hb_ot_map_feature_flags_t> {}; HB_MARK_AS_FLAG_T (hb_ot_map_feature_flags_t);
/* Macro version for where const is desired. */ /* Macro version for where const is desired. */
#define F_COMBINE(l,r) (hb_ot_map_feature_flags_t ((unsigned int) (l) | (unsigned int) (r))) #define F_COMBINE(l,r) (hb_ot_map_feature_flags_t ((unsigned int) (l) | (unsigned int) (r)))

View File

@ -119,6 +119,15 @@ extern "C" void hb_free_impl(void *ptr);
#define HB_FUNC __func__ #define HB_FUNC __func__
#endif #endif
/* Use templates for bitwise ops on enums or MSVC's DEFINE_ENUM_FLAG_OPERATORS */
#ifdef _MSC_VER
# pragma warning(disable:4200)
# pragma warning(disable:4800)
# define HB_MARK_AS_FLAG_T(flags_t) DEFINE_ENUM_FLAG_OPERATORS (##flags_t##);
#else
# define HB_MARK_AS_FLAG_T(flags_t) template <> class hb_mark_as_flags_t<flags_t> {};
#endif
/* /*
* Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411 * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411
* HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch * HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch
@ -895,6 +904,7 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3)
/* To my surprise, looks like the function resolver is happy to silently cast /* To my surprise, looks like the function resolver is happy to silently cast
* one enum to another... So this doesn't provide the type-checking that I * one enum to another... So this doesn't provide the type-checking that I
* originally had in mind... :( */ * originally had in mind... :( */
#ifndef _MSC_VER
template <class T> class hb_mark_as_flags_t; template <class T> class hb_mark_as_flags_t;
template <class T> static inline T operator | (T l, T r) template <class T> static inline T operator | (T l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; return T ((unsigned int) l | (unsigned int) r); } { hb_mark_as_flags_t<T> unused HB_UNUSED; return T ((unsigned int) l | (unsigned int) r); }
@ -906,6 +916,7 @@ template <class T> static inline T& operator |= (T &l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; l = l | r; return l; } { hb_mark_as_flags_t<T> unused HB_UNUSED; l = l | r; return l; }
template <class T> static inline T& operator &= (T& l, T r) template <class T> static inline T& operator &= (T& l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; l = l & r; return l; } { hb_mark_as_flags_t<T> unused HB_UNUSED; l = l & r; return l; }
#endif
/* Useful for set-operations on small enums. /* Useful for set-operations on small enums.