gnucash master: Prevent localizing the decimal point in gcc<5.

John Ralls jralls at code.gnucash.org
Mon Feb 20 19:55:48 EST 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/75e6a41b (commit)
	from  https://github.com/Gnucash/gnucash/commit/cbe52dad (commit)



commit 75e6a41bd784856f822d622271d1dde7a3355986
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Feb 20 16:51:06 2017 -0800

    Prevent localizing the decimal point in gcc<5.
    
    Apparently gcc V4.8 provides a defective implementation of
    std::locale which first doesn't support std::numpunct and second
    throws the wrong exception type.
    
    Unfortunately boost::locale isn't a solution because it uses the
    gcc facets.
    
    So for now, we don't compile that bit if gcc is too old.

diff --git a/src/libqof/qof/gnc-numeric.hpp b/src/libqof/qof/gnc-numeric.hpp
index b72eef6..a0bf0c3 100644
--- a/src/libqof/qof/gnc-numeric.hpp
+++ b/src/libqof/qof/gnc-numeric.hpp
@@ -26,6 +26,7 @@
 #include <string>
 #include <iostream>
 #include <locale>
+#include <typeinfo> // For std::bad_cast exception
 #include "gnc-rational-rounding.hpp"
 
 class GncRational;
@@ -349,12 +350,13 @@ std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>&
     std::locale loc = s.getloc();
     ss.imbue(loc);
     char dec_pt = '.';
+#if __GNUC__ >= 5
     try
     {
         dec_pt = std::use_facet<std::numpunct<char>>(loc).decimal_point();
     }
     catch(const std::bad_cast& err) {} //Don't do anything, num_sep is already set.
-
+#endif
     ss.copyfmt(s);
     ss.width(0);
     if (n.denom() == 1)
diff --git a/src/libqof/qof/test/gtest-gnc-numeric.cpp b/src/libqof/qof/test/gtest-gnc-numeric.cpp
index 34f56b1..8aa3aef 100644
--- a/src/libqof/qof/test/gtest-gnc-numeric.cpp
+++ b/src/libqof/qof/test/gtest-gnc-numeric.cpp
@@ -211,6 +211,7 @@ TEST(gncnumeric_stream, output_stream)
     GncNumeric rational_string(123, 456);
     output << rational_string;
     EXPECT_EQ("123/456", output.str());
+#if __GNUC__ >= 5
     output.imbue(std::locale("de_DE"));
     output.str("");
     output << simple_int;
@@ -221,6 +222,7 @@ TEST(gncnumeric_stream, output_stream)
     output.str("");
     output << rational_string;
     EXPECT_EQ("123/456", output.str());
+#endif
 }
 
 TEST(gncnumeric_stream, input_stream)



Summary of changes:
 src/libqof/qof/gnc-numeric.hpp            | 4 +++-
 src/libqof/qof/test/gtest-gnc-numeric.cpp | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)



More information about the gnucash-changes mailing list