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


Kristian Spangsege 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.

No. Unless it is bound to a const reference, the temporary is destroyed at the end of the statement, not at the end of the scope.



Bo Persson



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