diff --git a/Packets/Packet.test.cc b/Packets/Packet.test.cc index 8c28f73b58e1685f96c9a3de6737442194e28735..dd8d1738de07fa6f26966cd6dd0ada8c728c3b27 100644 --- a/Packets/Packet.test.cc +++ b/Packets/Packet.test.cc @@ -28,6 +28,7 @@ // Custom includes #include <sstream> +#include <boost/static_assert.hpp> #include "Packets.hh" #include "../Utils/auto_unit_test.hh" @@ -126,6 +127,11 @@ namespace { struct ComplexEmptyAnnotation : senf::ComplexAnnotation {}; + struct InvalidAnnotation + { + std::string value; + }; + } BOOST_AUTO_UNIT_TEST(packet) @@ -273,6 +279,24 @@ BOOST_AUTO_UNIT_TEST(packetAnnotation) BOOST_CHECK( ! senf::detail::AnnotationIndexer<ComplexEmptyAnnotation>::Small ); } +#ifdef COMPILE_CHECK + +COMPILE_FAIL(invalidAnnotation) +{ +# ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS + + senf::Packet packet (FooPacket::create()); + (void) packet.annotation<InvalidAnnotation>(); + +# else + + BOOST_STATIC_ASSERT(( false )); + +# endif +} + +#endif + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ diff --git a/Packets/PacketImpl.hh b/Packets/PacketImpl.hh index 4aa2d8c1f63065a5963c48fe893304743532f326..4b13fdd31704b3ca53a6010751252bea945f3790 100644 --- a/Packets/PacketImpl.hh +++ b/Packets/PacketImpl.hh @@ -31,6 +31,7 @@ #include <vector> #include <boost/utility.hpp> #include <boost/type_traits/is_base_of.hpp> +#include <boost/static_assert.hpp> #include "../Utils/pool_alloc_mixin.hh" #include "PacketTypes.hh" #include "../Utils/singleton.hh" @@ -91,8 +92,14 @@ namespace detail { AnnotationIndexer(); unsigned index_; static unsigned index(); - static bool const Small = (sizeof(Annotation) <= sizeof(AnnotationEntry) - && ! boost::is_base_of<ComplexAnnotation, Annotation>::value); + static bool const Complex = boost::is_base_of<ComplexAnnotation, Annotation>::value; + static bool const Small = (sizeof(Annotation) <= sizeof(AnnotationEntry) && ! Complex); + +# ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS + + BOOST_STATIC_ASSERT(( boost::is_pod<Annotation>::value || Complex )); + +# endif }; template <class Annotation, bool Small = AnnotationIndexer<Annotation>::Small>