From c42cf37f61717a7db778899d95473b0c128e45e2 Mon Sep 17 00:00:00 2001 From: g0dil <g0dil@wiback.org> Date: Tue, 4 Nov 2008 13:23:04 +0000 Subject: [PATCH] Packets: Add ComplexAnnotation check for current (4.3) g++ Versions using boost::is_pod --- Packets/Packet.test.cc | 24 ++++++++++++++++++++++++ Packets/PacketImpl.hh | 11 +++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Packets/Packet.test.cc b/Packets/Packet.test.cc index 8c28f73b..dd8d1738 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 4aa2d8c1..4b13fdd3 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> -- GitLab