This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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
2005-01-20  Christopher Jefferson <chris@bubblescope.net>

	* testsuite/21_strings/basic_string/element_access/char/empty.cc:
	Remove invalid test on non-const std::string.
	* testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc:
	Likewise.
Index: testsuite/21_strings/basic_string/element_access/char/empty.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/empty.cc,v
retrieving revision 1.1
diff -u -r1.1 empty.cc
--- testsuite/21_strings/basic_string/element_access/char/empty.cc	28 Sep 2004 08:58:32 -0000	1.1
+++ testsuite/21_strings/basic_string/element_access/char/empty.cc	20 Jan 2005 19:58:03 -0000
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -32,12 +32,6 @@
 int main()
 {
   bool test __attribute__((unused)) = true;
-  
-  {
-    std::string empty;
-    char c = empty[0];
-    VERIFY( c == char() );
-  }
 
   {
     const std::string empty;
Index: testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc,v
retrieving revision 1.1
diff -u -r1.1 empty.cc
--- testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc	28 Sep 2004 08:58:33 -0000	1.1
+++ testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc	20 Jan 2005 19:58:03 -0000
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -34,12 +34,6 @@
   bool test __attribute__((unused)) = true;
   
   {
-    std::wstring empty;
-    wchar_t c = empty[0];
-    VERIFY( c == wchar_t() );
-  }
-
-  {
     const std::wstring empty;
     wchar_t c = empty[0];
     VERIFY( c == wchar_t() );

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]