From f034839f103ffb31342e36d5a4d75d3c323ad27f Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Tue, 10 Jun 2014 09:56:58 -0400 Subject: [PATCH] Work around bugs in Visual C++ variadic macro parsing and/or non-standard use of same. Compiles on win32 and linux, whether it works is anyone's guess. --- include/fc/exception/exception.hpp | 6 ++++-- include/fc/log/logger.hpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/fc/exception/exception.hpp b/include/fc/exception/exception.hpp index 894f575..4b1a12a 100644 --- a/include/fc/exception/exception.hpp +++ b/include/fc/exception/exception.hpp @@ -297,10 +297,12 @@ namespace fc do { throw EXCEPTION_TYPE( FC_LOG_MESSAGE( error, "", FC_FORMAT_ARG_PARAMS(__VA_ARGS__) ) ); } while(false); //#define FC_THROW( FORMAT, ... ) - +// FC_INDIRECT_EXPAND workas around a bug in Visual C++ variadic macro processing that prevents it +// from separating __VA_ARGS__ into separate tokens +#define FC_INDIRECT_EXPAND(MACRO, ARGS) MACRO ARGS #define FC_THROW( ... ) \ do { \ - throw fc::exception( FC_LOG_MESSAGE( error, __VA_ARGS__ ) ); \ + throw fc::exception( FC_INDIRECT_EXPAND(FC_LOG_MESSAGE, ( error, __VA_ARGS__ )) ); \ } while(0) #define FC_EXCEPTION( EXCEPTION_TYPE, FORMAT, ... ) \ diff --git a/include/fc/log/logger.hpp b/include/fc/log/logger.hpp index 221e709..a885cfd 100644 --- a/include/fc/log/logger.hpp +++ b/include/fc/log/logger.hpp @@ -131,8 +131,10 @@ namespace fc #define FC_FORMAT( SEQ )\ BOOST_PP_SEQ_FOR_EACH( FC_FORMAT_ARG, v, SEQ ) -#define FC_FORMAT_ARG_PARAMS( SEQ )\ - BOOST_PP_SEQ_FOR_EACH( FC_FORMAT_ARGS, v, SEQ ) +// takes a ... instead of a SEQ arg because it can be called with an empty SEQ +// from FC_CAPTURE_AND_THROW() +#define FC_FORMAT_ARG_PARAMS( ... )\ + BOOST_PP_SEQ_FOR_EACH( FC_FORMAT_ARGS, v, __VA_ARGS__ ) #define idump( SEQ ) \ ilog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) )