From 6037b312a67c1f60802e4cd88492be5f0dd7c7b8 Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Thu, 28 Jul 2005 06:42:33 +0000 Subject: [PATCH] error on incomplete types, void fix git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@186 7ec92016-0320-0410-acc4-a06ded1c099a --- include/loki/TypeManip.h | 65 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/include/loki/TypeManip.h b/include/loki/TypeManip.h index 84fc50b..9fc6ef2 100644 --- a/include/loki/TypeManip.h +++ b/include/loki/TypeManip.h @@ -174,8 +174,34 @@ struct SuperSubclass enum { value = (::Loki::Conversion::exists && !::Loki::Conversion::sameType) }; - // Dummy data member to make sure that both classes are fully defined. - char dummy[sizeof (T) + sizeof (U)]; + // Dummy enum to make sure that both classes are fully defined. + enum{ dontUseWithIncompleteTypes = ( sizeof (T) == sizeof (U) ) }; +}; + +template <> +struct SuperSubclass +{ + enum { value = false }; +}; + +template +struct SuperSubclass +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType) }; + + // Dummy enum to make sure that both classes are fully defined. + enum{ dontUseWithIncompleteTypes = ( 0 == sizeof (U) ) }; +}; + +template +struct SuperSubclass +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType) }; + + // Dummy enum to make sure that both classes are fully defined. + enum{ dontUseWithIncompleteTypes = ( sizeof (T) == 0 ) }; }; //////////////////////////////////////////////////////////////////////////////// @@ -193,10 +219,39 @@ struct SuperSubclassStrict !::Loki::Conversion::sameType && !::Loki::Conversion::sameType) }; - // Dummy data member to make sure that both classes are fully defined. - char dummy[sizeof (T) + sizeof (U)]; + // Dummy enum to make sure that both classes are fully defined. + enum{ dontUseWithIncompleteTypes = ( sizeof (T) == sizeof (U) ) }; }; +template<> +struct SuperSubclassStrict +{ + enum { value = false }; +}; + +template +struct SuperSubclassStrict +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType && + !::Loki::Conversion::sameType) }; + + // Dummy enum to make sure that both classes are fully defined. + enum{ dontUseWithIncompleteTypes = ( 0 == sizeof (U) ) }; +}; + +template +struct SuperSubclassStrict +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType && + !::Loki::Conversion::sameType) }; + + // Dummy enum to make sure that both classes are fully defined. + enum{ dontUseWithIncompleteTypes = ( sizeof (T) == 0 ) }; +}; + + } // namespace Loki //////////////////////////////////////////////////////////////////////////////// @@ -238,7 +293,7 @@ struct SuperSubclassStrict // macros are deprecated. // Added extra parenthesis in sizeof in Conversion, to disambiguate function // call from function declaration. T.S. -// July 27, 2005 : compiler error on using Sub/Super with incomplete types +// July 27, 2005 : compiler error on using SuperSubclass/Strict with incomplete types // (credit due to Mark Stevans) ////////////////////////////////////////////////////////////////////////////////