summaryrefslogtreecommitdiffstats
path: root/libcxx/test/strings/basic.string
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2013-11-06 14:24:38 +0000
committerMarshall Clow <mclow.lists@gmail.com>2013-11-06 14:24:38 +0000
commite42732232752f9c4b099cd15f23d0c319e9e3c38 (patch)
tree08ff4227c0937b7d83a34fb8e8c1f74c132f61a2 /libcxx/test/strings/basic.string
parent10e316a68ec247f01a9a6fb33e83ff7d630aa4a9 (diff)
downloadbcm5719-llvm-e42732232752f9c4b099cd15f23d0c319e9e3c38.tar.gz
bcm5719-llvm-e42732232752f9c4b099cd15f23d0c319e9e3c38.zip
Fix an off-by-one error in basic_string::__grow_by, where it would incorrectly throw length_error (instead of bad_alloc) when attempting to resize the string to 'max_size()'. Add tests for resizing to max_size +/-1
llvm-svn: 194151
Diffstat (limited to 'libcxx/test/strings/basic.string')
-rw-r--r--libcxx/test/strings/basic.string/string.capacity/max_size.pass.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/libcxx/test/strings/basic.string/string.capacity/max_size.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/max_size.pass.cpp
index f9b228412c7..0fe7f123c89 100644
--- a/libcxx/test/strings/basic.string/string.capacity/max_size.pass.cpp
+++ b/libcxx/test/strings/basic.string/string.capacity/max_size.pass.cpp
@@ -18,15 +18,45 @@
template <class S>
void
-test(const S& s)
+test1(const S& s)
{
- assert(s.max_size() >= s.size());
- {
- S s2;
- try { s2.resize(s2.max_size() - 1, 'x'); }
+ S s2(s);
+ const size_t sz = s2.max_size() - 1;
+ try { s2.resize(sz, 'x'); }
catch ( const std::bad_alloc & ) { return ; }
+ assert ( s2.size() == sz );
+}
+
+template <class S>
+void
+test2(const S& s)
+{
+ S s2(s);
+ const size_t sz = s2.max_size();
+ try { s2.resize(sz, 'x'); }
+ catch ( const std::bad_alloc & ) { return ; }
+ assert ( s.size() == sz );
+}
+
+template <class S>
+void
+test3(const S& s)
+{
+ S s2(s);
+ const size_t sz = s2.max_size() + 1;
+ try { s2.resize(sz, 'x'); }
+ catch ( const std::length_error & ) { return ; }
assert ( false );
- }
+}
+
+template <class S>
+void
+test(const S& s)
+{
+ assert(s.max_size() >= s.size());
+ test1(s);
+ test2(s);
+ test3(s);
}
int main()
OpenPOWER on IntegriCloud