diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 67c431d39cdc657af95abe382310313e46abc82e..ceccecdce933247521e5f4d4de4276ccedc007cc 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -48,8 +48,8 @@ ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20); ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)); -template <> class hb_mark_as_flags_t {}; -template <> class hb_mark_as_flags_t {}; +HB_MARK_AS_FLAG_T (hb_buffer_flags_t); +HB_MARK_AS_FLAG_T (hb_buffer_serialize_flags_t); enum hb_buffer_scratch_flags_t { 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_COMPLEX3 = 0x08000000u, }; -template <> class hb_mark_as_flags_t {}; +HB_MARK_AS_FLAG_T (hb_buffer_scratch_flags_t); /* diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 04958a816e8312bf86f4948165b8960b008d16e4..5b21f1427660cee8f5e00a1c539a765fbf81428f 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -581,7 +581,7 @@ struct LookupFlag : USHORT } /* namespace OT */ /* This has to be outside the namespace. */ -template <> class hb_mark_as_flags_t {}; +HB_MARK_AS_FLAG_T (OT::LookupFlag::Flags); namespace OT { struct Lookup diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index 049b232de0768357f750dab3dce96d96e5eb9d99..45897ed5a81c5e29fe4830f3e96495e10e126d29 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -65,7 +65,7 @@ enum hb_ot_layout_glyph_props_flags_t HB_OT_LAYOUT_GLYPH_PROPS_LIGATED | HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED }; -template <> class hb_mark_as_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_GEN_CAT = 0x1Fu }; -template <> class hb_mark_as_flags_t {}; +HB_MARK_AS_FLAG_T (hb_unicode_props_flags_t); static inline void _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_buffer_t *buffer) diff --git a/src/hb-ot-map-private.hh b/src/hb-ot-map-private.hh index 1e3ff67e3372ec239d00938c24ba2036bfd76e5f..6f62c77de0babc50244b065a138ae9061cfe8ada 100644 --- a/src/hb-ot-map-private.hh +++ b/src/hb-ot-map-private.hh @@ -159,7 +159,7 @@ enum hb_ot_map_feature_flags_t { 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. */ }; -template <> class hb_mark_as_flags_t {}; +HB_MARK_AS_FLAG_T (hb_ot_map_feature_flags_t); /* Macro version for where const is desired. */ #define F_COMBINE(l,r) (hb_ot_map_feature_flags_t ((unsigned int) (l) | (unsigned int) (r))) diff --git a/src/hb-private.hh b/src/hb-private.hh index 5ed7ff3b20c6203ec45dd1c4b4f60b49926dd623..32f8d5e370492982d90533934f9fcc73ea06b976 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -119,6 +119,15 @@ extern "C" void hb_free_impl(void *ptr); #define HB_FUNC __func__ #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 {}; +#endif + /* * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411 * 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 * one enum to another... So this doesn't provide the type-checking that I * originally had in mind... :( */ +#ifndef _MSC_VER template class hb_mark_as_flags_t; template static inline T operator | (T l, T r) { hb_mark_as_flags_t unused HB_UNUSED; return T ((unsigned int) l | (unsigned int) r); } @@ -906,6 +916,7 @@ template static inline T& operator |= (T &l, T r) { hb_mark_as_flags_t unused HB_UNUSED; l = l | r; return l; } template static inline T& operator &= (T& l, T r) { hb_mark_as_flags_t unused HB_UNUSED; l = l & r; return l; } +#endif /* Useful for set-operations on small enums.