summaryrefslogtreecommitdiff
path: root/test/libcxx/strings/basic.string/string.modifiers
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 11:07:56 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 11:07:56 +0000
commitf36202620b428c45a1c8d91743727c9313424fb2 (patch)
tree14928d8970ba4890a6370aca4c38fc832d45f21f /test/libcxx/strings/basic.string/string.modifiers
parent0294ba5648d889e48ffee8ddad25944e258940ae (diff)
Notes
Diffstat (limited to 'test/libcxx/strings/basic.string/string.modifiers')
-rw-r--r--test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp b/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
new file mode 100644
index 000000000000..920c0d185261
--- /dev/null
+++ b/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// Call __clear_and_shrink() and ensure string invariants hold
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+ std::string l = "Long string so that allocation definitely, for sure, absolutely happens. Probably.";
+ std::string s = "short";
+
+ assert(l.__invariants());
+ assert(s.__invariants());
+
+ s.__clear_and_shrink();
+ assert(s.__invariants());
+ assert(s.size() == 0);
+
+ {
+ std::string::size_type cap = l.capacity();
+ l.__clear_and_shrink();
+ assert(l.__invariants());
+ assert(l.size() == 0);
+ assert(l.capacity() < cap);
+ }
+}
+
+#else
+
+int main()
+{
+}
+
+#endif