From 282ce7230b8bd8ad65c408cdaf1499504038247d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 29 Nov 2018 12:18:14 -0500 Subject: [PATCH] Fix "typename outside template" issues Nothing an extra template class wouldn't fix... Fixes https://github.com/harfbuzz/harfbuzz/issues/1419 --- src/hb-null.hh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/hb-null.hh b/src/hb-null.hh index 1583d5b90..dde4b2e95 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -77,6 +77,7 @@ struct hb_static_size /* * Null() */ + extern HB_INTERNAL hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)]; @@ -86,7 +87,13 @@ static inline Type const & Null (void) { static_assert (hb_null_size (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); return *reinterpret_cast (_hb_NullPool); } -#define Null(Type) Null () +template +struct NullHelper +{ + typedef typename hb_remove_const (typename hb_remove_reference (QType)) Type; + static inline const Type & get_null (void) { return Null (); } +}; +#define Null(Type) NullHelper::get_null () /* Specializations for arbitrary-content Null objects expressed in bytes. */ #define DECLARE_NULL_NAMESPACE_BYTES(Namespace, Type) \ @@ -129,17 +136,23 @@ static inline Type& Crap (void) { memcpy (obj, &Null(Type), sizeof (*obj)); return *obj; } -#define Crap(Type) Crap () +template +struct CrapHelper +{ + typedef typename hb_remove_const (typename hb_remove_reference (QType)) Type; + static inline Type & get_crap (void) { return Crap (); } +}; +#define Crap(Type) CrapHelper::get_crap () template -struct CrapOrNull { +struct CrapOrNullHelper { static inline Type & get (void) { return Crap(Type); } }; template -struct CrapOrNull { - static inline Type const & get (void) { return Null(Type); } +struct CrapOrNullHelper { + static inline const Type & get (void) { return Null(Type); } }; -#define CrapOrNull(Type) CrapOrNull::get () +#define CrapOrNull(Type) CrapOrNullHelper::get () /*