From bae365b02c22fe6da2b8c51d28e533afb6f0ccd7 Mon Sep 17 00:00:00 2001 From: Pawel Kurowski Date: Fri, 28 Feb 2020 10:59:23 +0100 Subject: [PATCH] Ensure existence of required channel constructor (only MSVC) Declaring constructor = default was allowing aggressive optimization. Compiler would skip both channel registration, and static asserts. --- Src/Common/MWR/C3/Internals/AutomaticRegistrator.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h b/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h index ff65012..01ddc18 100644 --- a/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h +++ b/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h @@ -11,13 +11,16 @@ namespace MWR::C3 template struct Register : AbstractType { - Register() + virtual ~Register() { - // Addressing variable in constructor prevents compiler from skipping template instantiation, because of possible side effects. + // Addressing variable in virtual destructor prevents compiler from skipping template instantiation, because of possible side effects. + // Similar effect can be achieved in gcc with attribute 'used' + // Clang can ignore both approaches, if Iface does not declare any custom constructor. static_cast(m_Registered); static_cast(s_InterfaceHash); } + private: /// Main function responsible for registration of interface. /// Return value of function is used to initialize static variable assuring execution of code before main. /// @returns true. @@ -27,7 +30,6 @@ namespace MWR::C3 return InterfaceFactory::Instance().Register(Iface::s_InterfaceHash, CreateInterfaceData()); } - private: template class EnsureDefaultCapability {