@@ -138,6 +138,10 @@ namespace tfm = tinyformat;
138138#include < iostream>
139139#include < sstream>
140140
141+ #ifndef TINYFORMAT_ASSERT
142+ # define TINYFORMAT_ASSERT (cond ) assert (cond)
143+ #endif
144+
141145#ifndef TINYFORMAT_ERROR
142146# define TINYFORMAT_ERROR (reason ) assert (0 && reason)
143147#endif
@@ -211,7 +215,7 @@ template<int n> struct is_wchar<wchar_t[n]> {};
211215template <typename T, typename fmtT, bool convertible = is_convertible<T, fmtT>::value>
212216struct formatValueAsType
213217{
214- static void invoke (std::ostream& /* out*/ , const T& /* value*/ ) { assert (0 ); }
218+ static void invoke (std::ostream& /* out*/ , const T& /* value*/ ) { TINYFORMAT_ASSERT (0 ); }
215219};
216220// Specialized version for types that can actually be converted to fmtT, as
217221// indicated by the "convertible" template parameter.
@@ -488,7 +492,11 @@ namespace detail {
488492class FormatArg
489493{
490494 public:
491- FormatArg () {}
495+ FormatArg ()
496+ : m_value(NULL ),
497+ m_formatImpl (NULL ),
498+ m_toIntImpl(NULL )
499+ { }
492500
493501 template <typename T>
494502 FormatArg (const T& value)
@@ -500,11 +508,15 @@ class FormatArg
500508 void format (std::ostream& out, const char * fmtBegin,
501509 const char * fmtEnd, int ntrunc) const
502510 {
511+ TINYFORMAT_ASSERT (m_value);
512+ TINYFORMAT_ASSERT (m_formatImpl);
503513 m_formatImpl (out, fmtBegin, fmtEnd, ntrunc, m_value);
504514 }
505515
506516 int toInt () const
507517 {
518+ TINYFORMAT_ASSERT (m_value);
519+ TINYFORMAT_ASSERT (m_toIntImpl);
508520 return m_toIntImpl (m_value);
509521 }
510522
@@ -705,23 +717,27 @@ inline const char* streamStateFromFormat(std::ostream& out, bool& spacePadPositi
705717 break ;
706718 case ' X' :
707719 out.setf (std::ios::uppercase);
720+ // Falls through
708721 case ' x' : case ' p' :
709722 out.setf (std::ios::hex, std::ios::basefield);
710723 intConversion = true ;
711724 break ;
712725 case ' E' :
713726 out.setf (std::ios::uppercase);
727+ // Falls through
714728 case ' e' :
715729 out.setf (std::ios::scientific, std::ios::floatfield);
716730 out.setf (std::ios::dec, std::ios::basefield);
717731 break ;
718732 case ' F' :
719733 out.setf (std::ios::uppercase);
734+ // Falls through
720735 case ' f' :
721736 out.setf (std::ios::fixed, std::ios::floatfield);
722737 break ;
723738 case ' G' :
724739 out.setf (std::ios::uppercase);
740+ // Falls through
725741 case ' g' :
726742 out.setf (std::ios::dec, std::ios::basefield);
727743 // As in boost::format, let stream decide float format.
@@ -866,18 +882,18 @@ class FormatListN : public FormatList
866882 { static_assert (sizeof ...(args) == N, " Number of args must be N" ); }
867883#else // C++98 version
868884 void init (int ) {}
869- # define TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR (n ) \
870- \
871- template <TINYFORMAT_ARGTYPES(n)> \
872- FormatListN (TINYFORMAT_VARARGS(n)) \
873- : FormatList(&m_formatterStore[0 ], n) \
874- { assert (n == N); init (0 , TINYFORMAT_PASSARGS (n)); } \
875- \
876- template <TINYFORMAT_ARGTYPES(n)> \
877- void init (int i, TINYFORMAT_VARARGS(n)) \
878- { \
879- m_formatterStore[i] = FormatArg (v1); \
880- init (i+1 TINYFORMAT_PASSARGS_TAIL (n)); \
885+ # define TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR (n ) \
886+ \
887+ template <TINYFORMAT_ARGTYPES(n)> \
888+ FormatListN (TINYFORMAT_VARARGS(n)) \
889+ : FormatList(&m_formatterStore[0 ], n) \
890+ { TINYFORMAT_ASSERT (n == N); init (0 , TINYFORMAT_PASSARGS (n)); } \
891+ \
892+ template <TINYFORMAT_ARGTYPES(n)> \
893+ void init (int i, TINYFORMAT_VARARGS(n)) \
894+ { \
895+ m_formatterStore[i] = FormatArg (v1); \
896+ init (i+1 TINYFORMAT_PASSARGS_TAIL (n)); \
881897 }
882898
883899 TINYFORMAT_FOREACH_ARGNUM (TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR)
0 commit comments