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.
This commit is contained in:
John Ralls 2017-02-20 16:51:06 -08:00
parent cbe52dad34
commit 75e6a41bd7
2 changed files with 5 additions and 1 deletions

View File

@ -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)

View File

@ -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)