public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: bkoz@gcc.gnu.org
To: bkoz@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org
Subject: Re: libstdc++/1704
Date: Fri, 25 May 2001 11:36:00 -0000	[thread overview]
Message-ID: <20010525183600.28719.qmail@sourceware.cygnus.com> (raw)

The following reply was made to PR libstdc++/1704; it has been noted by GNATS.

From: bkoz@gcc.gnu.org
To: nicolai.josuttis@braunschweig.netsurf.de, bkoz@gcc.gnu.org,
  bkoz@redhat.com, gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org,
  pcarlini@unitus.it
Cc:  
Subject: Re: libstdc++/1704
Date: 25 May 2001 18:33:15 -0000

 Synopsis: Null output from Josuttis example
 
 Responsible-Changed-From-To: unassigned->bkoz
 Responsible-Changed-By: bkoz
 Responsible-Changed-When: Fri May 25 11:33:14 2001
 Responsible-Changed-Why:
     Mine.
 State-Changed-From-To: analyzed->feedback
 State-Changed-By: bkoz
 State-Changed-When: Fri May 25 11:33:14 2001
 State-Changed-Why:
     I don't thing this is a bug, really. 
     In particular,
     c = std::toupper(c, getloc());
     
     where c == int_type attempts to instantiate
     
       template<typename _CharT>
         inline _CharT 
         toupper(_CharT __c, const locale& __loc)
         { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
     
     with _CharT == int. This is allowed, but keep in mind that the standard locale doesn't have ctype<int> as a standard facet, so thus use_facet has to fail:
     
       template<typename _Facet>
         const _Facet&
         use_facet(const locale& __loc)
         {
           typedef locale::_Impl::__vec_facet        __vec_facet;
           size_t __i = _Facet::id._M_index;
           __vec_facet* __facet = __loc._M_impl->_M_facets;
           const locale::facet* __fp = (*__facet)[__i]; 
           if (__fp == 0 || __i >= __facet->size())
             __throw_bad_cast();
           return static_cast<const _Facet&>(*__fp);
         }
     
     
     So, std::bad_cast gets thrown here. This is, I believe, standard conformant behavior. To use ctype<int>, you'd have to imbue it in the standard locale (and then add some kind of ctype<int> functionality, which is of course a bit of a job.)
     
     Instead, I suggest casting the argument to toupper to either char or wchart_t, so that the standard ctype facets are used. I suspect this is the intent of the code.
     
     Nico?
     
     -benjamin
     
     
     class outbuf : public std::streambuf
     {
     protected:
       virtual int_type overflow(int_type c) 
       {
         if (c != EOF) 
           {
     	// convert lowercase to uppercase
     	try
     	  {
     	    //	    c = std::toupper(static_cast<char>(c), getloc());
     	    c = std::toupper(c, getloc());
     	  }
     	catch (std::exception& obj)
     	  {
     	    puts("trying to use ctype<int> in a locale that doesn't have it");
     	  }
     	    
     	// and write the character to the standard output
     	if (std::putchar(c) == EOF)
     	  return EOF;
           }
         return c;
       }
     };
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=1704&database=gcc


             reply	other threads:[~2001-05-25 11:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-25 11:36 bkoz [this message]
2001-05-28  6:16 libstdc++/1704 Paolo Carlini
2001-05-28 12:26 libstdc++/1704 Benjamin Kosnik
2001-06-05 18:36 libstdc++/1704 bkoz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010525183600.28719.qmail@sourceware.cygnus.com \
    --to=bkoz@gcc.gnu.org \
    --cc=gcc-prs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).