public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/34449]  New: use_facet<xxx_byname>(locale::classic()) returns true
@ 2007-12-13  4:53 sebor at roguewave dot com
  2007-12-13  5:42 ` [Bug libstdc++/34449] " sebor at roguewave dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: sebor at roguewave dot com @ 2007-12-13  4:53 UTC (permalink / raw)
  To: gcc-bugs

The test case below is expected to pass. With gcc 4.1.2 it aborts in the second
assert.

$ cat t.cpp && g++ t.cpp && ./a.out
#include <cassert>
#include <locale>

struct DerivedCtype: std::ctype_byname<char> {
    DerivedCtype (): std::ctype_byname<char>("") { }
};

template <class Facet>
bool check_use_facet (const std::locale &locale)
{
    try {
        std::use_facet<Facet>(locale);
    }
    catch (...) {
        return false;
    }
    return true;
}


int main ()
{
    const std::locale classic = std::locale::classic ();
    const std::locale named ("en_US.ISO-8859-1");
    const std::locale user (classic, new DerivedCtype);

    assert (check_use_facet<std::ctype<char> >(classic));
    assert (!check_use_facet<std::ctype_byname<char> >(classic));
    assert (!check_use_facet<DerivedCtype>(classic));

    assert (check_use_facet<std::ctype<char> >(named));
    assert (check_use_facet<std::ctype_byname<char> >(named));
    assert (!check_use_facet<DerivedCtype>(named));

    assert (check_use_facet<std::ctype<char> >(user));
    assert (check_use_facet<std::ctype_byname<char> >(user));
    assert (check_use_facet<DerivedCtype>(user));
}
a.out: t.cpp:28: int main(): Assertion
`!check_use_facet<std::ctype_byname<char>
 >(classic)' failed.


-- 
           Summary: use_facet<xxx_byname>(locale::classic()) returns true
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebor at roguewave dot com
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
@ 2007-12-13  5:42 ` sebor at roguewave dot com
  2007-12-13 16:55 ` bkoz at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sebor at roguewave dot com @ 2007-12-13  5:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from sebor at roguewave dot com  2007-12-13 05:41 -------
FWIW, it looks like you need a dynamic_cast in use_facet (it's not enough to
check the id and then downcast using static_cast). Something like this:

--- locale_facets.tcc 2007-10-21 08:33:43.000000000 -0600
+++ locale_facets.tcc 2007-12-12 22:28:07.000000000 -0700
@@ -111,9 +111,13 @@
     {
       const size_t __i = _Facet::id._M_id();
       const locale::facet** __facets = __loc._M_impl->_M_facets;
+
+      const locale::facet* __pf;
       if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
-        __throw_bad_cast();
-      return static_cast<const _Facet&>(*__facets[__i]);
+        __pf = 0;
+      else
+        __pf = __facets[__i];
+      return dynamic_cast<const _Facet&>(*__pf);
     }

   // Routine to access a cache for the facet.  If the cache didn't


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
  2007-12-13  5:42 ` [Bug libstdc++/34449] " sebor at roguewave dot com
@ 2007-12-13 16:55 ` bkoz at gcc dot gnu dot org
  2007-12-14 18:56 ` bkoz at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2007-12-13 16:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bkoz at gcc dot gnu dot org  2007-12-13 16:54 -------

This and 3012 in progress..


-- 

bkoz at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |bkoz at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-12-13 16:54:51
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
  2007-12-13  5:42 ` [Bug libstdc++/34449] " sebor at roguewave dot com
  2007-12-13 16:55 ` bkoz at gcc dot gnu dot org
@ 2007-12-14 18:56 ` bkoz at gcc dot gnu dot org
  2007-12-14 19:32 ` bkoz at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2007-12-14 18:56 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 829 bytes --]



------- Comment #3 from bkoz at gcc dot gnu dot org  2007-12-14 18:56 -------

The only thing that I have issue with is this part:

   assert (check_use_facet<std::ctype_byname<char> >(named));

There is no verbiage in the standard that specifies that named locales use the
_byname facets. This is implied in the test case given.

I'm looking in N2461 at 22.1.1.2,  where the const char* locale constructors
were added. There is no specification of byname facets.

>From 22.1.1.1.2

  For some standard facets a standard “. . ._byname” class, derived from it,
implements the virtual function semantics equivalent to that facet of the
locale constructed by locale(const char*) with the same name.

This doesn't actually require what this code asserts.

;)

-benjamin


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
                   ` (2 preceding siblings ...)
  2007-12-14 18:56 ` bkoz at gcc dot gnu dot org
@ 2007-12-14 19:32 ` bkoz at gcc dot gnu dot org
  2007-12-14 19:36 ` sebor at roguewave dot com
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2007-12-14 19:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bkoz at gcc dot gnu dot org  2007-12-14 19:32 -------
Subject: Bug 34449

Author: bkoz
Date: Fri Dec 14 19:32:03 2007
New Revision: 130941

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130941
Log:
2007-12-14  Benjamin Kosnik  <bkoz@redhat.com>

        PR libstdc++/30127
        PR libstdc++/34449
        * include/bits/locale_classes.h (use_facet): Check facet hierarchy.
        (has_facet): Same.
        * testsuite/22_locale/global_templates/user_facet_hierarchies.cc: New.
        * testsuite/22_locale/global_templates/
        standard_facet_hierarchies.cc: New.


Added:
   
trunk/libstdc++-v3/testsuite/22_locale/global_templates/standard_facet_hierarchies.cc
   
trunk/libstdc++-v3/testsuite/22_locale/global_templates/user_facet_hierarchies.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/locale_classes.h


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
                   ` (3 preceding siblings ...)
  2007-12-14 19:32 ` bkoz at gcc dot gnu dot org
@ 2007-12-14 19:36 ` sebor at roguewave dot com
  2007-12-14 21:25 ` bkoz at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sebor at roguewave dot com @ 2007-12-14 19:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from sebor at roguewave dot com  2007-12-14 19:35 -------
(In reply to comment #3)

That's an interesting interpretation. I agree it's possible although I suspect
it was not intended. IMO, the _byname facets are really an implementation
detail that was exposed just to show how the facet machinery was meant to be
implemented. The other gaping hole in the spec, besides the missing requirement
that a named locale actually use the _byname facets, is the effects of their
constructors. I.e., what do I get when I invoke
std::ctype_byname<wchar_t>("en_US.ISO-8859-1")? (Do I get the same behavior I
with the ctype facet in locale("en_US.ISO-8859-1") or something else?)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
                   ` (4 preceding siblings ...)
  2007-12-14 19:36 ` sebor at roguewave dot com
@ 2007-12-14 21:25 ` bkoz at gcc dot gnu dot org
  2007-12-14 21:27 ` bkoz at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2007-12-14 21:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from bkoz at gcc dot gnu dot org  2007-12-14 21:25 -------

Hey Martin! I agree, things are kind of wonky here. Certainly, changing
libstdc++ to have named locales implemented via the _byname facets would not be
hard. If it were specified, of course.

IMO, the _byname complexity is pointless, and these derived facets should be
folded into the base facet classes. 

Then, the spec would be quite clear, as there would be only one way to do this.

-benjamin


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
                   ` (5 preceding siblings ...)
  2007-12-14 21:25 ` bkoz at gcc dot gnu dot org
@ 2007-12-14 21:27 ` bkoz at gcc dot gnu dot org
  2007-12-14 21:30 ` bkoz at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2007-12-14 21:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from bkoz at gcc dot gnu dot org  2007-12-14 21:27 -------
Subject: Bug 34449

Author: bkoz
Date: Fri Dec 14 21:27:09 2007
New Revision: 130944

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130944
Log:
2007-12-14  Benjamin Kosnik  <bkoz@redhat.com>

        PR libstdc++/30127
        PR libstdc++/34449
        * include/bits/locale_classes.h (use_facet): Check facet hierarchy.
        (has_facet): Same.
        * testsuite/22_locale/global_templates/user_facet_hierarchies.cc: New.
        * testsuite/22_locale/global_templates/
        standard_facet_hierarchies.cc: New.


Added:
   
branches/gcc-4_2-branch/libstdc++-v3/testsuite/22_locale/global_templates/standard_facet_hierarchies.cc
   
branches/gcc-4_2-branch/libstdc++-v3/testsuite/22_locale/global_templates/user_facet_hierarchies.cc
Modified:
    branches/gcc-4_2-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_2-branch/libstdc++-v3/include/bits/locale_facets.tcc


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
                   ` (6 preceding siblings ...)
  2007-12-14 21:27 ` bkoz at gcc dot gnu dot org
@ 2007-12-14 21:30 ` bkoz at gcc dot gnu dot org
  2007-12-25 14:56 ` pcarlini at suse dot de
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2007-12-14 21:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from bkoz at gcc dot gnu dot org  2007-12-14 21:30 -------

This is fixed in mainline and 4_2-branch. It could certainly be put on the
4_1-branch as well, but I don't have that checked out ATM.

I'd rather open a new bug/enhancement request for the named locale to _byname
facet linkage issue. Your call, of course.

best,
benjamin


-- 

bkoz at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.2.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
                   ` (7 preceding siblings ...)
  2007-12-14 21:30 ` bkoz at gcc dot gnu dot org
@ 2007-12-25 14:56 ` pcarlini at suse dot de
  2008-01-05 11:15 ` paolo at gcc dot gnu dot org
  2008-01-05 11:48 ` pcarlini at suse dot de
  10 siblings, 0 replies; 12+ messages in thread
From: pcarlini at suse dot de @ 2007-12-25 14:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from pcarlini at suse dot de  2007-12-25 14:55 -------
Fixed for 4.2.3.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
                   ` (8 preceding siblings ...)
  2007-12-25 14:56 ` pcarlini at suse dot de
@ 2008-01-05 11:15 ` paolo at gcc dot gnu dot org
  2008-01-05 11:48 ` pcarlini at suse dot de
  10 siblings, 0 replies; 12+ messages in thread
From: paolo at gcc dot gnu dot org @ 2008-01-05 11:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from paolo at gcc dot gnu dot org  2008-01-05 11:05 -------
Subject: Bug 34449

Author: paolo
Date: Sat Jan  5 11:04:43 2008
New Revision: 131334

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131334
Log:
2008-01-05  Paolo Carlini  <pcarlini@suse.de>

        PR libstdc++/34680

        Revert:
        2007-12-17  Jonathan Wakely  <jwakely.gcc@gmail.com>
        * include/bits/locale_facets.tcc (has_facet, use_facet): Simplify
        RTTI checks.

        2007-12-14  Benjamin Kosnik  <bkoz@redhat.com>

        PR libstdc++/30127
        PR libstdc++/34449
        * include/bits/locale_facets.tcc (use_facet): Check facet hierarchy.
        (has_facet): Same.
        * testsuite/22_locale/global_templates/user_facet_hierarchies.cc: New.
        * testsuite/22_locale/global_templates/
        standard_facet_hierarchies.cc: New.

Removed:
   
branches/gcc-4_2-branch/libstdc++-v3/testsuite/22_locale/global_templates/standard_facet_hierarchies.cc
   
branches/gcc-4_2-branch/libstdc++-v3/testsuite/22_locale/global_templates/user_facet_hierarchies.cc
Modified:
    branches/gcc-4_2-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_2-branch/libstdc++-v3/include/bits/locale_facets.tcc


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libstdc++/34449] use_facet<xxx_byname>(locale::classic()) returns true
  2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
                   ` (9 preceding siblings ...)
  2008-01-05 11:15 ` paolo at gcc dot gnu dot org
@ 2008-01-05 11:48 ` pcarlini at suse dot de
  10 siblings, 0 replies; 12+ messages in thread
From: pcarlini at suse dot de @ 2008-01-05 11:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from pcarlini at suse dot de  2008-01-05 11:06 -------
Fixed for 4.3.0 only, in the branch the patch has been reverted.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.2.3                       |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34449


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-01-05 11:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-13  4:53 [Bug libstdc++/34449] New: use_facet<xxx_byname>(locale::classic()) returns true sebor at roguewave dot com
2007-12-13  5:42 ` [Bug libstdc++/34449] " sebor at roguewave dot com
2007-12-13 16:55 ` bkoz at gcc dot gnu dot org
2007-12-14 18:56 ` bkoz at gcc dot gnu dot org
2007-12-14 19:32 ` bkoz at gcc dot gnu dot org
2007-12-14 19:36 ` sebor at roguewave dot com
2007-12-14 21:25 ` bkoz at gcc dot gnu dot org
2007-12-14 21:27 ` bkoz at gcc dot gnu dot org
2007-12-14 21:30 ` bkoz at gcc dot gnu dot org
2007-12-25 14:56 ` pcarlini at suse dot de
2008-01-05 11:15 ` paolo at gcc dot gnu dot org
2008-01-05 11:48 ` pcarlini at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).