From f36202620b428c45a1c8d91743727c9313424fb2 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 28 Jul 2018 11:07:56 +0000 Subject: Vendor import of libc++ trunk r338150: https://llvm.org/svn/llvm-project/libcxx/trunk@338150 --- .../string.modifiers/clear_and_shrink_db1.pass.cpp | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp (limited to 'test/libcxx/strings/basic.string/string.modifiers') 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. +// +//===----------------------------------------------------------------------===// + +// + +// 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 +#include + +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 -- cgit v1.3