[MacPorts] #15653: std::locale broken in gcc

MacPorts noreply at macports.org
Tue Jun 17 11:46:59 PDT 2008


#15653: std::locale broken in gcc
--------------------------------+-------------------------------------------
 Reporter:  dirk at code-shop.com  |       Owner:  macports-tickets at lists.macosforge.org
     Type:  defect              |      Status:  new                                  
 Priority:  Normal              |   Milestone:                                       
Component:  ports               |     Version:  1.6.0                                
 Keywords:                      |  
--------------------------------+-------------------------------------------
 When compiling the following code:

 #include <locale>
 #include <iostream>
 #include <exception>
 #include <clocale>

 void
 try_c_locale(const char* locale_name)
 {
     if( std::setlocale(LC_ALL, locale_name) == NULL )
         printf("Failed to setlocale(LC_ALL, \"%s\")\n", locale_name);
     else
         printf("Succeeded in calling setlocale(LC_ALL, \"%s\")\n",
 locale_name);
 }

 void
 try_cpp_locale(const char* locale_name)
 {
     try
     {
         std::locale my_locale(locale_name);
     }
     catch(std::exception& e)
     {
         printf("Failed ctor for std::locale with \"%s\": %s\n",
 locale_name, e.what());
         return;
     }

     printf("Succeeded ctor for std::locale with \"%s\"\n", locale_name);
 }

 int
 main(void)
 {
     // Some locales from "locale -a" on my OS X system, here is proof
     // that these locales do exist on my system. Take my word for it
     // that "locale -a" also shows these locales existing on my linux
     // system as well.
     //
     // rutski at imac:~$ locale -a | tail -n 2
     // C
     // POSIX
     // rutski at imac:~$ locale -a | grep en_US
     // en_US
     // en_US.ISO8859-1
     // en_US.ISO8859-15
     // en_US.US-ASCII
     // en_US.UTF-8
     // rutski at imac:~$ locale -a | grep pl_PL
     // pl_PL
     // pl_PL.ISO8859-2
     // pl_PL.UTF-8
     // rutski at imac:~$

     const char* test_locales[] =
     {
         "C",
         "POSIX",
         "en_US",
         "en_US.UTF-8",
          "pl_PL",
         "pl_PL.ISO8859-2"
     };

     printf("Trying c locales...\n");
     for(size_t x = 0; x < sizeof(test_locales)/sizeof(char*); x++)
         try_c_locale(test_locales[x]);
     printf("\n");

     printf("Trying C++ locales...\n");
     for(size_t x = 0; x < sizeof(test_locales)/sizeof(char*); x++)
         try_cpp_locale(test_locales[x]);
 }

 the output clearly states there is something wrong:

 Trying c locales...
 Succeeded in calling setlocale(LC_ALL, "C")
 Succeeded in calling setlocale(LC_ALL, "POSIX")
 Succeeded in calling setlocale(LC_ALL, "en_US")
 Succeeded in calling setlocale(LC_ALL, "en_US.UTF-8")
 Succeeded in calling setlocale(LC_ALL, "pl_PL")
 Succeeded in calling setlocale(LC_ALL, "pl_PL.ISO8859-2")

 Trying C++ locales...
 Succeeded ctor for std::locale with "C"
 Succeeded ctor for std::locale with "POSIX"
 Failed ctor for std::locale with "en_US":
 locale::facet::_S_create_c_locale name not valid
 Failed ctor for std::locale with "en_US.UTF-8":
 locale::facet::_S_create_c_locale name not valid
 Failed ctor for std::locale with "pl_PL":
 locale::facet::_S_create_c_locale name not valid
 Failed ctor for std::locale with "pl_PL.ISO8859-2":
 locale::facet::_S_create_c_locale name not valid

 a google serach delivers this:

 http://groups.google.com/group/gnu.gcc.help/browse_thread/thread/99d874aed6b46fdd

 appearantly, a --enable-clocale to configure might do something

 however, macport's configure stage does not allow for adding options (or I
 could not find it)

 * could this be fixed in gcc? (in libstdc++)
 * could this be added to macport (adding extra configure options)

-- 
Ticket URL: <http://trac.macports.org/ticket/15653>
MacPorts <http://www.macports.org/>
Ports system for Mac OS


More information about the macports-tickets mailing list