This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [patch] std::string::operator[] extension in debug mode
Douglas Gregor <doug.gregor@gmail.com> writes:
| On May 19, 2005, at 3:14 PM, Gabriel Dos Reis wrote:
|
| > Jonathan Wakely <cow@compsoc.man.ac.uk> writes:
| >
| > | On Thu, May 19, 2005 at 08:04:31PM +0200, Gabriel Dos Reis wrote:
| > |
| > | > A question I have is why conditionalizing the extern template
| > stuff on
| > | > debug does not work.
| > |
| > | Because the lib was not built with debug, so the extern template
| > | instantiation (sans assertions) is always in the lib.
| >
| > If the lib was not build with debug and user wants to use it as with
| > debug support, then user is in trouble he/she asked for.
|
| The libstdc++ debug mode was specifically designed so that there is
| only one version of the compiled libstdc++ library, which may be
| linked with user applications that are compiled with -D_GLIBCXX_DEBUG
| and without (or even mixing code compiled with the different
| flags).
Thanks for the reminder; last time I checked, I followed the
realization in libstdc++, especially objected to the unspeakable hacks
in its initial version and was behing the "strong using" to support
the debug mode.
| Strong using and some tricky namespace work makes this
| possible. The problem is that basic_string<> permeates libstdc++ so
| much that we can't pull the same tricks that we do with, e.g.,
| std::vector.
I'm not sure the problem is that std::string pearmeats so much
libstdc++, or our failure to properly tame the ORD violation.
| > | If you disable
| > | extern templates your .o file includes an implicit instantiation
| > (with
| > | assertions).
| >
| > I think I understand that part.
| >
| > | When you link to the lib you get ODR.
| >
| > But you don't have to put it in the non-debug lib.
| >
| > -- Gaby
|
| With respect to -D_GLIBCXX_DEBUG, there is no "debug lib" and
| "non-debug lib"; just one lib that's compiled without _GLIBCXX_DEBUG
| defined.
If you specify -DGLIBCXX_DEBUG, you're in a "debug lib"; if you don't
you are in a "non-debug lib".
At configure time, if user instructs us that he also wants to use the
"debug lib" later, then we should make the appropriate instantiation
for the std::string so that it gest found latter.
(If a function like std::string::operator[] is not inlined, it gets
emitted as a weak symbol -- assuming support for weak symobls -- that
can coexist with a normal symbol with no error. The only downside is
that the normal symbol may tend to take over is the function is not
inlined. But, it is almost harmless).
-- Gaby