Use static_assert instead of custom ASSERT_STATIC
diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 37380b4..1aa87b6 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh
@@ -45,8 +45,8 @@ #define HB_BUFFER_MAX_LEN_DEFAULT 0x3FFFFFFF /* Shaping more than a billion chars? Let us know! */ #endif -ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20); -ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)); +static_assert ((sizeof (hb_glyph_info_t) == 20), ""); +static_assert ((sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)), ""); HB_MARK_AS_FLAG_T (hb_buffer_flags_t); HB_MARK_AS_FLAG_T (hb_buffer_serialize_flags_t);
diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 171d101..25b798b 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc
@@ -130,7 +130,7 @@ while (size >= new_allocated) new_allocated += (new_allocated >> 1) + 32; - ASSERT_STATIC (sizeof (info[0]) == sizeof (pos[0])); + static_assert ((sizeof (info[0]) == sizeof (pos[0])), ""); if (unlikely (_hb_unsigned_int_mul_overflows (new_allocated, sizeof (info[0])))) goto done;
diff --git a/src/hb-cache-private.hh b/src/hb-cache-private.hh index 24957e1..91955b7 100644 --- a/src/hb-cache-private.hh +++ b/src/hb-cache-private.hh
@@ -35,8 +35,8 @@ template <unsigned int key_bits, unsigned int value_bits, unsigned int cache_bits> struct hb_cache_t { - ASSERT_STATIC (key_bits >= cache_bits); - ASSERT_STATIC (key_bits + value_bits - cache_bits < 8 * sizeof (unsigned int)); + static_assert ((key_bits >= cache_bits), ""); + static_assert ((key_bits + value_bits - cache_bits < 8 * sizeof (unsigned int)), ""); inline void clear (void) {
diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 2266140..5697939 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc
@@ -678,7 +678,7 @@ CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &active_features[j].rec.feature), CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &active_features[j].rec.setting) }; - ASSERT_STATIC (ARRAY_LENGTH (keys) == ARRAY_LENGTH (values)); + static_assert ((ARRAY_LENGTH (keys) == ARRAY_LENGTH (values)), ""); CFDictionaryRef dict = CFDictionaryCreate (kCFAllocatorDefault, (const void **) keys, (const void **) values,
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index d90d68c..9cd482a 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh
@@ -85,7 +85,7 @@ #define _DEFINE_INSTANCE_ASSERTION1(_line, _assertion) \ inline void _instance_assertion_on_line_##_line (void) const \ { \ - ASSERT_STATIC (_assertion); \ + static_assert ((_assertion), ""); \ ASSERT_INSTANCE_POD (*this); /* Make sure it's POD. */ \ } # define _DEFINE_INSTANCE_ASSERTION0(_line, _assertion) _DEFINE_INSTANCE_ASSERTION1 (_line, _assertion) @@ -136,7 +136,7 @@ /* Generic nul-content Null objects. */ template <typename Type> static inline const Type& Null (void) { - ASSERT_STATIC (sizeof (Type) <= sizeof (_NullPool)); + static_assert ((sizeof (Type) <= sizeof (_NullPool)), ""); return *CastP<Type> (_NullPool); } @@ -147,7 +147,7 @@ /*static*/ inline const Type& Null<Type> (void) { \ return *CastP<Type> (_Null##Type); \ } /* The following line really exists such that we end in a place needing semicolon */ \ -ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type)) +static_assert (Type::min_size + 1 <= sizeof (_Null##Type), "Null pool too small. Enlarge.") /* Accessor macro. */ #define Null(Type) Null<Type>()
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 578d850..f22d990 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh
@@ -690,7 +690,7 @@ inline unsigned int get_coverage (hb_codepoint_t glyph_id) const { int i = glyphArray.bsearch (glyph_id); - ASSERT_STATIC (((unsigned int) -1) == NOT_COVERED); + static_assert ((((unsigned int) -1) == NOT_COVERED), ""); return i; }
diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index 552df0f..99dda3a 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh
@@ -404,9 +404,9 @@ { unsigned int klass = get_glyph_class (glyph); - ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH == (unsigned int) LookupFlag::IgnoreBaseGlyphs); - ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE == (unsigned int) LookupFlag::IgnoreLigatures); - ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK == (unsigned int) LookupFlag::IgnoreMarks); + static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH == (unsigned int) LookupFlag::IgnoreBaseGlyphs), ""); + static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE == (unsigned int) LookupFlag::IgnoreLigatures), ""); + static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK == (unsigned int) LookupFlag::IgnoreMarks), ""); switch (klass) { default: return 0;
diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 977e583..ecf45f1 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc
@@ -321,7 +321,7 @@ hb_tag_t script_tag, unsigned int *script_index) { - ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); + static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), ""); const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); if (g.find_script_index (script_tag, script_index)) @@ -352,7 +352,7 @@ unsigned int *script_index, hb_tag_t *chosen_script) { - ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); + static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), ""); const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); while (*script_tags) @@ -411,7 +411,7 @@ hb_tag_t feature_tag, unsigned int *feature_index) { - ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX); + static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), ""); const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); unsigned int num_features = g.get_feature_count (); @@ -448,7 +448,7 @@ hb_tag_t language_tag, unsigned int *language_index) { - ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX); + static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX), ""); const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); if (s.find_lang_sys_index (language_tag, language_index)) @@ -527,7 +527,7 @@ const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); - ASSERT_STATIC (sizeof (unsigned int) == sizeof (hb_tag_t)); + static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), ""); unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags); if (feature_tags) { @@ -548,7 +548,7 @@ hb_tag_t feature_tag, unsigned int *feature_index) { - ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX); + static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), ""); const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); @@ -859,7 +859,7 @@ unsigned int *lookup_count /* IN/OUT */, unsigned int *lookup_indexes /* OUT */) { - ASSERT_STATIC (OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX); + static_assert ((OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX), ""); const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); const OT::Feature &f = g.get_feature_variation (feature_index, variations_index);
diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc index 5764a11..0922d75 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc
@@ -138,7 +138,7 @@ const int *coords, unsigned int num_coords) { - ASSERT_STATIC (!(HB_GLYPH_FLAG_DEFINED & (HB_GLYPH_FLAG_DEFINED + 1))); + static_assert ((!(HB_GLYPH_FLAG_DEFINED & (HB_GLYPH_FLAG_DEFINED + 1))), ""); unsigned int global_bit_mask = HB_GLYPH_FLAG_DEFINED + 1; unsigned int global_bit_shift = _hb_popcount32 (HB_GLYPH_FLAG_DEFINED);
diff --git a/src/hb-ot-math-table.hh b/src/hb-ot-math-table.hh index 191d79e..3607dbe 100644 --- a/src/hb-ot-math-table.hh +++ b/src/hb-ot-math-table.hh
@@ -463,8 +463,8 @@ out.end_connector_length = font->em_scale (endConnectorLength, scale); out.full_advance = font->em_scale (fullAdvance, scale); - ASSERT_STATIC ((unsigned int) HB_MATH_GLYPH_PART_FLAG_EXTENDER == - (unsigned int) PartFlags::Extender); + static_assert ((unsigned int) HB_MATH_GLYPH_PART_FLAG_EXTENDER == + (unsigned int) PartFlags::Extender, ""); out.flags = (hb_ot_math_glyph_part_flags_t) (unsigned int)
diff --git a/src/hb-ot-shape-complex-arabic-fallback.hh b/src/hb-ot-shape-complex-arabic-fallback.hh index d97d285..92f6cdf 100644 --- a/src/hb-ot-shape-complex-arabic-fallback.hh +++ b/src/hb-ot-shape-complex-arabic-fallback.hh
@@ -237,8 +237,8 @@ return false; const Manifest &manifest = reinterpret_cast<const Manifest&> (arabic_win1256_gsub_lookups.manifest); - ASSERT_STATIC (sizeof (arabic_win1256_gsub_lookups.manifestData) / sizeof (ManifestLookup) - <= ARABIC_FALLBACK_MAX_LOOKUPS); + static_assert (sizeof (arabic_win1256_gsub_lookups.manifestData) / sizeof (ManifestLookup) + <= ARABIC_FALLBACK_MAX_LOOKUPS, ""); /* TODO sanitize the table? */ unsigned j = 0; @@ -271,7 +271,7 @@ const hb_ot_shape_plan_t *plan, hb_font_t *font) { - ASSERT_STATIC (ARRAY_LENGTH_CONST(arabic_fallback_features) <= ARABIC_FALLBACK_MAX_LOOKUPS); + static_assert ((ARRAY_LENGTH_CONST(arabic_fallback_features) <= ARABIC_FALLBACK_MAX_LOOKUPS), ""); unsigned int j = 0; for (unsigned int i = 0; i < ARRAY_LENGTH(arabic_fallback_features) ; i++) {
diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index 051db22..c985026 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc
@@ -198,7 +198,7 @@ 0x1CEEu, 0x1CF1u))) { cat = OT_Symbol; - ASSERT_STATIC ((int) INDIC_SYLLABIC_CATEGORY_AVAGRAHA == OT_Symbol); + static_assert (((int) INDIC_SYLLABIC_CATEGORY_AVAGRAHA == OT_Symbol), ""); } else if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x17CDu, 0x17D1u) || u == 0x17CBu || u == 0x17D3u || u == 0x17DDu)) /* Khmer Various signs */
diff --git a/src/hb-ot-shape-complex-use.cc b/src/hb-ot-shape-complex-use.cc index ac3a248..4bfbfb8 100644 --- a/src/hb-ot-shape-complex-use.cc +++ b/src/hb-ot-shape-complex-use.cc
@@ -292,7 +292,7 @@ if (use_plan->arabic_plan) return; - ASSERT_STATIC (INIT < 4 && ISOL < 4 && MEDI < 4 && FINA < 4); + static_assert ((INIT < 4 && ISOL < 4 && MEDI < 4 && FINA < 4), ""); hb_mask_t masks[4], all_masks = 0; for (unsigned int i = 0; i < 4; i++) {
diff --git a/src/hb-private.hh b/src/hb-private.hh index 493a814..282c9fe 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh
@@ -100,7 +100,7 @@ #define _PASTE1(a,b) a##b #define _PASTE(a,b) _PASTE1(a,b) #define static_assert(e, msg) \ - HB_UNUSED typedef char _PASTE(assertion_failed_at_line_, __LINE__) [(e) ? 1 : -1] + HB_UNUSED typedef int _PASTE(static_assertion_failed_at_line_, __LINE__) [(e) ? 1 : -1] #endif // static_assert #endif // __cplusplus < 201103L @@ -267,10 +267,6 @@ #define HB_STMT_START do #define HB_STMT_END while (0) -#define _ASSERT_STATIC1(_line, _cond) HB_UNUSED typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] -#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond)) -#define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond)) - template <unsigned int cond> class hb_assert_constant_t; template <> class hb_assert_constant_t<1> {}; @@ -278,19 +274,19 @@ /* Lets assert int types. Saves trouble down the road. */ -ASSERT_STATIC (sizeof (int8_t) == 1); -ASSERT_STATIC (sizeof (uint8_t) == 1); -ASSERT_STATIC (sizeof (int16_t) == 2); -ASSERT_STATIC (sizeof (uint16_t) == 2); -ASSERT_STATIC (sizeof (int32_t) == 4); -ASSERT_STATIC (sizeof (uint32_t) == 4); -ASSERT_STATIC (sizeof (int64_t) == 8); -ASSERT_STATIC (sizeof (uint64_t) == 8); +static_assert ((sizeof (int8_t) == 1), ""); +static_assert ((sizeof (uint8_t) == 1), ""); +static_assert ((sizeof (int16_t) == 2), ""); +static_assert ((sizeof (uint16_t) == 2), ""); +static_assert ((sizeof (int32_t) == 4), ""); +static_assert ((sizeof (uint32_t) == 4), ""); +static_assert ((sizeof (int64_t) == 8), ""); +static_assert ((sizeof (uint64_t) == 8), ""); -ASSERT_STATIC (sizeof (hb_codepoint_t) == 4); -ASSERT_STATIC (sizeof (hb_position_t) == 4); -ASSERT_STATIC (sizeof (hb_mask_t) == 4); -ASSERT_STATIC (sizeof (hb_var_int_t) == 4); +static_assert ((sizeof (hb_codepoint_t) == 4), ""); +static_assert ((sizeof (hb_position_t) == 4), ""); +static_assert ((sizeof (hb_mask_t) == 4), ""); +static_assert ((sizeof (hb_var_int_t) == 4), ""); /* We like our types POD */ @@ -912,7 +908,7 @@ * one right now. Declaring a variable won't work as HB_UNUSED * is unusable on some platforms and unused types are less likely * to generate a warning than unused variables. */ - ASSERT_STATIC (sizeof (hb_assert_unsigned_t<T>) >= 0); + static_assert ((sizeof (hb_assert_unsigned_t<T>) >= 0), ""); /* The casts below are important as if T is smaller than int, * the subtract results will become a signed int! */ @@ -1027,7 +1023,7 @@ unsigned int i; hb_options_t opts; }; -ASSERT_STATIC (sizeof (int) == sizeof (hb_options_union_t)); +static_assert ((sizeof (int) == sizeof (hb_options_union_t)), ""); HB_INTERNAL void _hb_options_init (void);
diff --git a/src/hb-set-private.hh b/src/hb-set-private.hh index e2010d7..8cd02fb 100644 --- a/src/hb-set-private.hh +++ b/src/hb-set-private.hh
@@ -62,8 +62,8 @@ + (mask_bytes >= 16? 1 : 0) + 0; - ASSERT_STATIC (shift < sizeof (hb_codepoint_t) * 8); - ASSERT_STATIC (shift + num_bits <= sizeof (hb_codepoint_t) * 8); + static_assert ((shift < sizeof (hb_codepoint_t) * 8), ""); + static_assert ((shift + num_bits <= sizeof (hb_codepoint_t) * 8), ""); inline void init (void) { mask = 0; @@ -341,8 +341,8 @@ elt_t elts[ELTS]; /* XXX 8kb */ - ASSERT_STATIC (sizeof (elt_t) * 8 == BITS); - ASSERT_STATIC (sizeof (elt_t) * 8 * ELTS > MAX_G); + static_assert ((sizeof (elt_t) * 8 == BITS), ""); + static_assert ((sizeof (elt_t) * 8 * ELTS > MAX_G), ""); }; struct hb_frozen_set_t
diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index d25accd..8599106 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc
@@ -316,7 +316,7 @@ const char *enc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-"; UUID id; UuidCreate ((UUID*) &id); - ASSERT_STATIC (2 + 3 * (16/2) < LF_FACESIZE); + static_assert ((2 + 3 * (16/2) < LF_FACESIZE), ""); unsigned int name_str_len = 0; face_name[name_str_len++] = 'F'; face_name[name_str_len++] = '_';