This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] libstdc++/30127/34449
- From: "Jonathan Wakely" <jwakely dot gcc at gmail dot com>
- To: "Benjamin Kosnik" <bkoz at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Sat, 15 Dec 2007 22:59:55 +0000
- Subject: Re: [v3] libstdc++/30127/34449
- References: <20071214134119.11416621@concorde.artheist.org>
On 14/12/2007, Benjamin Kosnik <bkoz@redhat.com> wrote:
> Fixes for use_facet/has_facet: now facet hierarchy is checked, to make
> sure that use of derived-facet methods properly error when the locale
> only has the base facet.
Unless I'm missing something, these changes will affect performance
more than necessary.
In has_facet, the dynamic_cast to a pointer type cannot throw so is
the try-catch needed?
In use_facet, if the first dynamic_cast works, the second will too, so
there's no point doing it twice.
Something like this still pass the new tests.
Jon
Index: include/bits/locale_classes.h
===================================================================
--- include/bits/locale_classes.h (revision 130956)
+++ include/bits/locale_classes.h (working copy)
@@ -579,17 +579,8 @@
{
const size_t __i = _Facet::id._M_id();
const locale::facet** __facets = __loc._M_impl->_M_facets;
- bool __b(false);
- try
- {
- if (__i < __loc._M_impl->_M_facets_size
- && dynamic_cast<const _Facet*>(__facets[__i]) != NULL)
- __b = true;
-
- }
- catch (...)
- { }
- return __b;
+ return __i < __loc._M_impl->_M_facets_size
+ && dynamic_cast<const _Facet*>(__facets[__i]) != NULL;
}
/**
@@ -611,8 +602,7 @@
{
const size_t __i = _Facet::id._M_id();
const locale::facet** __facets = __loc._M_impl->_M_facets;
- if (__i >= __loc._M_impl->_M_facets_size
- || dynamic_cast<const _Facet*>(__facets[__i]) == NULL)
+ if (__i >= __loc._M_impl->_M_facets_size || __facets[__i] == NULL)
__throw_bad_cast();
return dynamic_cast<const _Facet&>(*__facets[__i]);
}