This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Fix libstdc++/34680 in mainline
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Mon, 07 Jan 2008 02:06:27 +0100
- Subject: [Patch] Fix libstdc++/34680 in mainline
Hi,
now that __GXX_RTTI is available, it's possible to fix the two offending
uses. A subtle point is that, in order to consistently use across
optimization levels the available exported extern template
instantiations, we have to remove the inline specifier: probably, this
is still not bullet proof, but at least I checked that plain calls are
never inlined from -Os to -O3. Another observation, I'm not attempting
anything sophisticated on the other existing uses of run-time type
identification (i.e., dynamic_cast, typeid), in the debug-mode and TR1
implementations, where we are not risking any regression.
Tested x86_64-linux.
Paolo.
////////////////////
2008-01-07 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/34680
* include/bits/locale_classes.h (has_facet<>, use_facet<>): Do not
use dynamic_cast when run-time type identification is disabled; do
not mark inline.
Index: include/bits/locale_classes.h
===================================================================
--- include/bits/locale_classes.h (revision 131370)
+++ include/bits/locale_classes.h (working copy)
@@ -1,7 +1,7 @@
// Locale support -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007
+// 2006, 2007, 2008
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -574,13 +574,17 @@
* @return true if locale contains a facet of type Facet, else false.
*/
template<typename _Facet>
- inline bool
+ bool
has_facet(const locale& __loc) throw()
{
const size_t __i = _Facet::id._M_id();
const locale::facet** __facets = __loc._M_impl->_M_facets;
- return __i < __loc._M_impl->_M_facets_size
- && dynamic_cast<const _Facet*>(__facets[__i]) != NULL;
+ return (__i < __loc._M_impl->_M_facets_size
+#ifdef __GXX_RTTI
+ && dynamic_cast<const _Facet*>(__facets[__i]));
+#else
+ && static_cast<const _Facet*>(__facets[__i]));
+#endif
}
/**
@@ -597,14 +601,18 @@
* @throw std::bad_cast if locale doesn't contain a facet of type Facet.
*/
template<typename _Facet>
- inline const _Facet&
+ const _Facet&
use_facet(const locale& __loc)
{
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 || __facets[__i] == NULL)
+ if (__i >= __loc._M_impl->_M_facets_size || !__facets[__i])
__throw_bad_cast();
+#ifdef __GXX_RTTI
return dynamic_cast<const _Facet&>(*__facets[__i]);
+#else
+ return static_cast<const _Facet&>(*__facets[__i]);
+#endif
}