This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [patch] Remove invalid test on non-const empty strings
- From: chris jefferson <caj at cs dot york dot ac dot uk>
- To: Paolo Carlini <pcarlini at suse dot de>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 21 Jan 2005 09:02:32 +0000
- Subject: Re: [patch] Remove invalid test on non-const empty strings
- References: <41F01164.708@cs.york.ac.uk> <41F049E5.5070604@suse.de>
Paolo Carlini wrote:
Chris Jefferson wrote:
As we are testing empty strings, size()==0. Therefore we can only
perform the operation "s[0]" where s is the empty string when s is
const (when s[0] will return charT()). When s is non-const the
operation is undefined. The test tries to access s[0] on an empty
string s on both const and non-const strings. Therefore this patch
fixes things up.
I see your point, but I think the issue is somewhat debatable, and
much more general, actually. In this sense: according to 21.3.4, as
you point out above, "the behavior is undefined". Now, it happens,
that, *given our current implementation*, if things are not broken, we
mus return '\0' in this case too.
Therefore, the general issue is the following: should our testsuite
only test what the standard mandates or, when appropriate, request, so
to speak, "more" from the code, for instance specific behaviors when
the behavior is strictly speaking undefined? I don't think we have a
very rigorous policy about this issue and, frankly, being an
implementor that cares about *regressions* and *unexpected* changes of
behavior, that is not being a seller of a "conformancy testsuite", I
think the latter interpretation has its own advantages, in some cases.
What do other people think?
Good point!
Perhaps then a better idea would be to wrap tests like this in a #ifndef
_GLIBCXX_DEBUG / #endif pair?