From bd0067ee769e571acdf398124ab3b81a40e39ba1 Mon Sep 17 00:00:00 2001 From: "Daniel.Perry" Date: Tue, 25 Nov 2014 18:01:09 -0500 Subject: [PATCH 1/3] made code compile under windows with level 4 warnings --- format.cc | 26 ++++++++++++++++++++++++++ format.h | 12 ++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/format.cc b/format.cc index 76988b49..362e702a 100644 --- a/format.cc +++ b/format.cc @@ -84,6 +84,7 @@ using fmt::internal::Arg; #if _MSC_VER # pragma warning(push) # pragma warning(disable: 4127) // conditional expression is constant +# pragma warning(disable: 4702) // unreachable code #endif namespace { @@ -239,6 +240,8 @@ void check_sign(const Char *&s, const Arg &arg) { // left alignment if it is negative. class WidthHandler : public fmt::internal::ArgVisitor { private: + WidthHandler& operator=(WidthHandler const&); //no impl + fmt::FormatSpec &spec_; public: @@ -283,6 +286,8 @@ class PrecisionHandler : template class ArgConverter : public fmt::internal::ArgVisitor, void> { private: + ArgConverter& operator=(ArgConverter const&); //no impl + fmt::internal::Arg &arg_; wchar_t type_; @@ -321,6 +326,7 @@ class ArgConverter : public fmt::internal::ArgVisitor, void> { // Converts an integer argument to char for printf. class CharConverter : public fmt::internal::ArgVisitor { private: + CharConverter& operator=(CharConverter const&); // no impl fmt::internal::Arg &arg_; public: @@ -525,6 +531,8 @@ template class fmt::internal::ArgFormatter : public fmt::internal::ArgVisitor, void> { private: + ArgFormatter& operator=(ArgFormatter const&); // no impl + fmt::BasicFormatter &formatter_; fmt::BasicWriter &writer_; fmt::FormatSpec &spec_; @@ -1124,6 +1132,24 @@ template int fmt::internal::CharTraits::format_float( wchar_t *buffer, std::size_t size, const wchar_t *format, unsigned width, int precision, long double value); +template <> template <> char* fmt::BasicWriter::append_float_length( char* format_ptr) { return format_ptr; } +template <> template <> wchar_t* fmt::BasicWriter::append_float_length( wchar_t* format_ptr) { return format_ptr; } + +template <> template <> char* fmt::BasicWriter::append_float_length( char* format_ptr) { return format_ptr; } +template <> template <> wchar_t* fmt::BasicWriter::append_float_length( wchar_t* format_ptr) { return format_ptr; } + +template <> template <> char* fmt::BasicWriter::append_float_length( char* format_ptr) +{ + *format_ptr++ = 'L'; + return format_ptr; +} + +template <> template <> wchar_t* fmt::BasicWriter::append_float_length( wchar_t* format_ptr) +{ + *format_ptr++ = 'L'; + return format_ptr; +} + #if _MSC_VER # pragma warning(pop) #endif diff --git a/format.h b/format.h index 3a2a0439..dfe04ec9 100644 --- a/format.h +++ b/format.h @@ -407,13 +407,16 @@ inline int getsign(double value) { return sign; } inline int isinfinity(double x) { return !_finite(x); } +inline int isinfinity( long double x) { return !_finite(static_cast(x)); } #endif +/* template struct IsLongDouble { enum {VALUE = 0}; }; template <> struct IsLongDouble { enum {VALUE = 1}; }; +*/ template class BasicCharTraits { @@ -996,6 +999,8 @@ class PrintfFormatter : private FormatterBase { template class BasicFormatter : private internal::FormatterBase { private: + BasicFormatter& operator=(BasicFormatter const&); // no impl + BasicWriter &writer_; const Char *start_; @@ -1496,6 +1501,9 @@ class BasicWriter { // Do not implement! void operator<<(typename internal::CharTraits::UnsupportedStrType); + template + Char* append_float_length(Char* format_ptr); + friend class internal::ArgFormatter; friend class internal::PrintfFormatter; @@ -1926,8 +1934,8 @@ void BasicWriter::write_double( *format_ptr++ = '.'; *format_ptr++ = '*'; } - if (internal::IsLongDouble::VALUE) - *format_ptr++ = 'L'; + + format_ptr = append_float_length(format_ptr); *format_ptr++ = type; *format_ptr = '\0'; From 334fc54b5d2eb0b4d3745262bc8bc3339f18d967 Mon Sep 17 00:00:00 2001 From: "Daniel.Perry" Date: Tue, 25 Nov 2014 18:03:54 -0500 Subject: [PATCH 2/3] removed unused code --- format.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/format.h b/format.h index dfe04ec9..1d1a6eb9 100644 --- a/format.h +++ b/format.h @@ -410,14 +410,6 @@ inline int isinfinity(double x) { return !_finite(x); } inline int isinfinity( long double x) { return !_finite(static_cast(x)); } #endif -/* -template -struct IsLongDouble { enum {VALUE = 0}; }; - -template <> -struct IsLongDouble { enum {VALUE = 1}; }; -*/ - template class BasicCharTraits { public: From 838dc1e1890b3dcabbccf0c4f1d2890eaf4a7b13 Mon Sep 17 00:00:00 2001 From: "Daniel.Perry" Date: Tue, 2 Dec 2014 10:20:27 -0500 Subject: [PATCH 3/3] move append_float_length specialization to the header --- format.cc | 18 ------------------ format.h | 12 +++++++++++- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/format.cc b/format.cc index 362e702a..fc414fac 100644 --- a/format.cc +++ b/format.cc @@ -1132,24 +1132,6 @@ template int fmt::internal::CharTraits::format_float( wchar_t *buffer, std::size_t size, const wchar_t *format, unsigned width, int precision, long double value); -template <> template <> char* fmt::BasicWriter::append_float_length( char* format_ptr) { return format_ptr; } -template <> template <> wchar_t* fmt::BasicWriter::append_float_length( wchar_t* format_ptr) { return format_ptr; } - -template <> template <> char* fmt::BasicWriter::append_float_length( char* format_ptr) { return format_ptr; } -template <> template <> wchar_t* fmt::BasicWriter::append_float_length( wchar_t* format_ptr) { return format_ptr; } - -template <> template <> char* fmt::BasicWriter::append_float_length( char* format_ptr) -{ - *format_ptr++ = 'L'; - return format_ptr; -} - -template <> template <> wchar_t* fmt::BasicWriter::append_float_length( wchar_t* format_ptr) -{ - *format_ptr++ = 'L'; - return format_ptr; -} - #if _MSC_VER # pragma warning(pop) #endif diff --git a/format.h b/format.h index 1d1a6eb9..4fd237fd 100644 --- a/format.h +++ b/format.h @@ -1494,7 +1494,7 @@ class BasicWriter { void operator<<(typename internal::CharTraits::UnsupportedStrType); template - Char* append_float_length(Char* format_ptr); + Char* append_float_length(Char* format_ptr) { return format_ptr; } friend class internal::ArgFormatter; friend class internal::PrintfFormatter; @@ -1981,6 +1981,16 @@ void BasicWriter::write_double( } } +template <> template <> inline char* BasicWriter::append_float_length( char* format_ptr) { + *format_ptr++ = 'L'; + return format_ptr; +} + +template <> template <> inline wchar_t* BasicWriter::append_float_length( wchar_t* format_ptr) { + *format_ptr++ = 'L'; + return format_ptr; +} + /** \rst This template provides operations for formatting and writing data into