This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Re: Segfault in simple use of codecvt<>


Turns out it's not limited to the 'codecvt' facet. The same type of
problem occurs with the 'ctype' facet.

On 1/12/08, Kristian Spangsege <kristian.spangsege@gmail.com> wrote:
> The code:
>
> > #include <cwchar>
> > #include <locale>
> >
> > int main()
> > {
> >   typedef std::codecvt<wchar_t, char, std::mbstate_t> cvt_type;
> >   cvt_type const &cvt = std::use_facet<cvt_type>(std::locale("en_US"));
> >   cvt.encoding();
> >   return 0;
> > }
>
> System:
>
> gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51)
>
> Fedora Core release 6 (Zod)
>
> Linux localhost.localdomain 2.6.20-1.2952.fc6 #1 SMP Wed May 16
> 18:59:18 EDT 2007 i686 i686 i386 GNU/Linux
>
> I specify no flags when compiling.
>
>
> The code works if I leave out "en_US":
>
> >   cvt_type const &cvt = std::use_facet<cvt_type>(std::locale());
> >   cvt.encoding();
>
>
> It also works if the passed locale is not a temporary:
>
> >   std::locale l("en_US");
> >   cvt_type const &cvt = std::use_facet<cvt_type>(l);
> >   cvt.encoding();
>
>
> And if 'encoding' is called directly on the returned facet:
>
> >   std::use_facet<cvt_type>(std::locale("en_US")).encoding();
>
>
> As far as I know, a temporary is supposed to stay "alive" until the
> end of the scope.
>
> Regards,
> Kristian
>


-- 
"Will robots inherit the earth? Yes, but they will be our children. We
owe our minds to the deaths and lives of all the creatures that were
ever engaged in the struggle called Evolution. Our job is to see that
all this work shall not end up in meaningless waste."
                                              -- MARVIN L. MINSKY


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