[patch] Remove invalid test on non-const empty strings

Paolo Carlini pcarlini@suse.de
Fri Jan 21 00:14:00 GMT 2005


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?

Paolo.



More information about the Libstdc++ mailing list