From 5021c4d88506ac19be4302be02c3cd1702f97d03 Mon Sep 17 00:00:00 2001 From: Douglas Heriot Date: Sat, 22 Aug 2015 02:05:40 +1000 Subject: Define GOOGLE_ATTRIBUTE_NOINLINE for MSVC. Workaround for VS2015 Release build compiler bug. See issue #240 - MSVC in VS2015 seems to inline a function it shouldn't. My original workaround was to disable inlining for the whole file, but I found a way to do it on just this specific function using __declspec(noinline). Unfortunately __declspec has to go at the start of the function declaration, while __attribute in GCC can go either before or after. I had to move lots of GOOGLE_ATTRIBUTE_NOLINE to make it compile. I have not yet tested this change with GCC. Will there be other side effects of defining this, given it wasn't previously? I also noticed a few functions marked with both the 'inline' keyword, and GOOGLE_ATTRIBUTE_NOINLINE - huh? Is there an explanation for this, or is it an oversight? --- src/google/protobuf/message.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/google/protobuf/message.cc') diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 276d7de5..123bd789 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -52,6 +52,7 @@ #include #include #include +#include namespace google { namespace protobuf { @@ -466,6 +467,10 @@ struct ShutdownRepeatedFieldRegister { namespace internal { template<> +#if defined(_MSC_VER) && (_MSC_VER >= 1900) +// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240 +GOOGLE_ATTRIBUTE_NOINLINE +#endif Message* GenericTypeHandler::NewFromPrototype( const Message* prototype, google::protobuf::Arena* arena) { return prototype->New(arena); -- cgit v1.2.3