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

Chris Jefferson caj@cs.york.ac.uk
Thu Jan 20 20:19:00 GMT 2005


Out of curiosity I tried running the libstdc++ debug library against the 
libstdc++ test suite. A few tests failed, and I intend to look through 
and try to fix them up, once I decide the nicest way to do it.

The only one which appears to have failed due to an actual error are
21_strings/basic_string/element_access/char/empty.cc
and the wchar_t version, which is testing 21.3.4.

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.

On a related note, there are a bunch of tests to check that the 
specialisations of swap work. These don't appear to work on the 
debugging library, and also make me nervous as they are adding overloads 
of member functions of elements of std. It seems their purpose is to 
check that the O(1) swap is being called. Wouldn't therefore something like:

#include<vector>
#include<algorithm>

int swaps;
struct T
{
  T() {}
  T(T& t) { ++swaps;}
};

int main(void)
{
swaps=0;
vector<T> a(10);
vector<T> b(10);
std::swap(a,b);
VERIFY(swaps==0);
}

Test the same thing, and not require adding overloads?

Chris
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CL_emptytest
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20050120/daf74f44/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch_emptytest
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20050120/daf74f44/attachment-0001.ksh>


More information about the Libstdc++ mailing list