This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/5110: num_put caches num_punct values



>Number:         5110
>Category:       libstdc++
>Synopsis:       num_put caches num_punct values
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 13 18:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     sebor@roguewave.com
>Release:        gcc 3.0.1
>Organization:
>Environment:

>Description:
The program below produces unexpected output and fails
with non-0 exit status. The expected output is 

123+456+78+9-1-234-567-89-123/456/789

and the expected exit status is 0. My guess is that it's
because num_put is caching the values supplied by numpunct,
which I don't believe is permitted in Stage 2 in 22.2.2.2.2.

Regards
Martin
>How-To-Repeat:
$ cat t.cpp
#include <iostream>
#include <locale>

int main ()
{
    struct Punct: std::numpunct<char> {
        string_type do_grouping () const {
            static const char *grp = "\1\2\3";
            return grp++;
        }

        char_type do_thousands_sep () const {
            static const char *sep = "+-/";
            return *sep++;
        }
    };


    std::locale l (std::cout.getloc (), (std::numpunct<char>*)new Punct);
    std::cout.imbue (l);

    std::cout << 123456789 << -123456789 << -123456789 << std::endl;

    return *std::use_facet<std::numpunct<char> >(std::cout.getloc ()).grouping (
).c_str ();
}

$ g++ t.cpp
$ ./a.out ; echo $?
123+456+78+9-123+456+78+9-123+456+78+9
2
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]