From c3448e8d21963eb7fc357a37a7a426a4bf130ef3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 15 Oct 2017 12:02:00 +0200 Subject: [PATCH] Use static_assert instead of custom ASSERT_STATIC --- src/hb-buffer-private.hh | 4 +-- src/hb-buffer.cc | 2 +- src/hb-cache-private.hh | 4 +-- src/hb-coretext.cc | 2 +- src/hb-open-type-private.hh | 6 ++-- src/hb-ot-layout-common-private.hh | 2 +- src/hb-ot-layout-gdef-table.hh | 6 ++-- src/hb-ot-layout.cc | 14 ++++----- src/hb-ot-map.cc | 2 +- src/hb-ot-math-table.hh | 4 +-- src/hb-ot-shape-complex-arabic-fallback.hh | 6 ++-- src/hb-ot-shape-complex-indic.cc | 2 +- src/hb-ot-shape-complex-use.cc | 2 +- src/hb-private.hh | 34 ++++++++++------------ src/hb-set-private.hh | 8 ++--- src/hb-uniscribe.cc | 2 +- util/options.cc | 3 +- 17 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 37380b40d..1aa87b65c 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 171d1016e..25b798b58 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -130,7 +130,7 @@ hb_buffer_t::enlarge (unsigned int size) 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 24957e1e9..91955b709 100644 --- a/src/hb-cache-private.hh +++ b/src/hb-cache-private.hh @@ -35,8 +35,8 @@ template 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 22661407d..56979391d 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -678,7 +678,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, 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 d90d68c59..9cd482adb 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -85,7 +85,7 @@ static inline Type& StructAfter(TObject &X) #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 @@ static const void *_NullPool[(256+8) / sizeof (void *)]; /* Generic nul-content Null objects. */ template static inline const Type& Null (void) { - ASSERT_STATIC (sizeof (Type) <= sizeof (_NullPool)); + static_assert ((sizeof (Type) <= sizeof (_NullPool)), ""); return *CastP (_NullPool); } @@ -147,7 +147,7 @@ template <> \ /*static*/ inline const Type& Null (void) { \ return *CastP (_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() diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 578d850c1..f22d990bc 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -690,7 +690,7 @@ struct CoverageFormat1 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 552df0fd8..99dda3a74 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -404,9 +404,9 @@ struct GDEF { 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 977e58301..ecf45f195 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -321,7 +321,7 @@ hb_ot_layout_table_find_script (hb_face_t *face, 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 @@ hb_ot_layout_table_choose_script (hb_face_t *face, 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_ot_layout_table_find_feature (hb_face_t *face, 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_ot_layout_script_find_language (hb_face_t *face, 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 @@ hb_ot_layout_language_get_feature_tags (hb_face_t *face, 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_ot_layout_language_find_feature (hb_face_t *face, 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 @@ hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face, 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 5764a1104..0922d7594 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc @@ -138,7 +138,7 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m, 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 191d79e98..3607dbea3 100644 --- a/src/hb-ot-math-table.hh +++ b/src/hb-ot-math-table.hh @@ -463,8 +463,8 @@ struct MathGlyphPartRecord 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 d97d28521..92f6cdf15 100644 --- a/src/hb-ot-shape-complex-arabic-fallback.hh +++ b/src/hb-ot-shape-complex-arabic-fallback.hh @@ -237,8 +237,8 @@ arabic_fallback_plan_init_win1256 (arabic_fallback_plan_t *fallback_plan, return false; const Manifest &manifest = reinterpret_cast (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 @@ arabic_fallback_plan_init_unicode (arabic_fallback_plan_t *fallback_plan, 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 051db22fc..c98502641 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -198,7 +198,7 @@ set_indic_properties (hb_glyph_info_t &info) 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 (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 ac3a24867..4bfbfb875 100644 --- a/src/hb-ot-shape-complex-use.cc +++ b/src/hb-ot-shape-complex-use.cc @@ -292,7 +292,7 @@ setup_topographical_masks (const hb_ot_shape_plan_t *plan, 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 493a8146b..282c9fe51 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -100,7 +100,7 @@ private: #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 @@ static inline unsigned int ARRAY_LENGTH (const Type (&)[n]) { return n; } #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 class hb_assert_constant_t; template <> class hb_assert_constant_t<1> {}; @@ -278,19 +274,19 @@ template <> class hb_assert_constant_t<1> {}; /* 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 @@ hb_in_range (T u, T lo, T hi) * 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) >= 0); + static_assert ((sizeof (hb_assert_unsigned_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 @@ union hb_options_union_t { 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 e2010d762..8cd02fbcb 100644 --- a/src/hb-set-private.hh +++ b/src/hb-set-private.hh @@ -62,8 +62,8 @@ struct hb_set_digest_lowest_bits_t + (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 @@ struct hb_set_t 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 d25accd56..85991069d 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -316,7 +316,7 @@ _hb_generate_unique_face_name (wchar_t *face_name, unsigned int *plen) 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++] = '_'; diff --git a/util/options.cc b/util/options.cc index 3aa6834dd..5b0fb14fe 100644 --- a/util/options.cc +++ b/util/options.cc @@ -486,7 +486,8 @@ font_options_t::add_options (option_parser_t *parser) char *text = NULL; { - ASSERT_STATIC (ARRAY_LENGTH_CONST (supported_font_funcs) > 0); + static_assert ((ARRAY_LENGTH_CONST (supported_font_funcs) > 0), + "No supported font-funcs found."); GString *s = g_string_new (NULL); g_string_printf (s, "Set font functions implementation to use (default: %s)\n\n Supported font function implementations are: %s", supported_font_funcs[0].name,