From f78ca808622f12cb6190bdd9a422f4bbb634336b Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Thu, 31 Jul 2014 20:10:19 -0700 Subject: [PATCH] Modifying DecorateImmediate to enhance diagnostics This routine cannot be called with zero arguments, anyway, and rather than a cryptic "zero sized array" error message, instead users will see that they are calling the function with the wrong number of arguments. --- autowiring/AutoPacket.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/autowiring/AutoPacket.h b/autowiring/AutoPacket.h index 4ffd103d8..19733441f 100644 --- a/autowiring/AutoPacket.h +++ b/autowiring/AutoPacket.h @@ -345,16 +345,17 @@ class AutoPacket: /// If multiple values are specified, all will be simultaneously made valid and /// then invalidated. /// - template - void DecorateImmediate(const Ts&... immeds) { + template + void DecorateImmediate(const T& immed, const Ts&... immeds) { // These are the things we're going to be working with while we perform immediate decoration: - static const std::type_info* sc_typeInfo [] = {&typeid(Ts)...}; - const void* pvImmeds[] = {&immeds...}; - DecorationDisposition* pTypeSubs[sizeof...(Ts)]; + static const std::type_info* sc_typeInfo [] = {&typeid(T), &typeid(Ts)...}; + const void* pvImmeds [] = {&immed, &immeds...}; + DecorationDisposition* pTypeSubs[1 + sizeof...(Ts)]; // None of the inputs may be shared pointers--if any of the inputs are shared pointers, they must be attached // to this packet via Decorate, or else dereferenced and used that way. static_assert( + !is_shared_ptr::value && !is_any...>::value, "DecorateImmediate must not be used to attach a shared pointer, use Decorate on such a decoration instead" ); @@ -362,7 +363,7 @@ class AutoPacket: // Perform standard decoration with a short initialization: { std::lock_guard lk(m_lock); - for(size_t i = 0; i < sizeof...(Ts); i++) { + for(size_t i = 0; i <= sizeof...(Ts); i++) { pTypeSubs[i] = &m_decorations[*sc_typeInfo[i]]; if(pTypeSubs[i]->wasCheckedOut) { std::stringstream ss; @@ -388,11 +389,11 @@ class AutoPacket: } // Now trigger a rescan to hit any deferred, unsatisfiable entries: - static const std::type_info* lamda_typeInfos [] = {&typeid(Ts)...}; + static const std::type_info* lamda_typeInfos [] = {&typeid(T), &typeid(Ts)...}; for(auto ti : lamda_typeInfos) MarkUnsatisfiable(*ti); }), - PulseSatisfaction(pTypeSubs, sizeof...(Ts)); + PulseSatisfaction(pTypeSubs, 1 + sizeof...(Ts)); } ///