money_get should heed frac_digits

Brendan Kehoe brendan@zen.org
Mon May 26 20:58:00 GMT 2003


In the standard, the definition of moneypunct says that you can't have a
value for frac_digits and ignore it:

   $22.2.6.3.3/8
   The number of digits required after the decimal point (if any) is exactly
   the value returned by frac_digits().

The libstdc++ implementation of money_get<...>::do_get doesn't enforce this,
which lets people use as many digits as they want.

The attached testcase, tfrac.cpp, shows the places where we shouldn't be
accepting what's being fed into money_get.

In tfrac-diffs.txt, I've presented one approach to correct this.  There is one
curious issue in the fix, though---the name "__sep_pos" is no longer correct.
It's being used both to note the thousands separator and, now, how far we've
gone past the decimal-point that came.

Another approach, aside from renaming it, is actually using a new variable to
count how far we've come since the decimal-point, and thus keeping them
separated.

I'll let you guys decide if you want to do anything about the naming of it,
and will provide a revised patch if there's a style you want to go with.

B

-- 
Brendan Kehoe                                               brendan@zen.org

http://www.zen.org/~brendan/
-------------- next part --------------
Index: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.98
diff -u -p -r1.98 locale_facets.tcc
--- include/bits/locale_facets.tcc	13 May 2003 20:13:14 -0000	1.98
+++ include/bits/locale_facets.tcc	26 May 2003 20:22:18 -0000
@@ -1271,6 +1271,18 @@ namespace std
       if (__c == __eof)
 	__err |= ios_base::eofbit;
 
+      // Iff not enough digits were supplied after the decimal-point.
+      if (__testdecfound)
+	{
+	  const int __frac = __intl ? __mpt.frac_digits() 
+				    : __mpf.frac_digits();
+	  if (__frac > 0)
+	    {
+	      if (__sep_pos != __frac)
+		__testvalid = false;
+	    }
+	}
+
       // Iff valid sequence is not recognized.
       if (!__testvalid || !__tmp_units.size())
 	__err |= ios_base::failbit;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tfrac.cpp
Type: text/x-c++src
Size: 1825 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20030526/d7104deb/attachment.bin>


More information about the Libstdc++ mailing list