diff --git a/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// basic_string() noexcept(is_nothrow_default_constructible::value); + +#include +#include + +#include "test_macros.h" +#include "test_allocator.h" + +#if TEST_STD_VER >= 11 +// Test the noexcept specification, which is a conforming extension +LIBCPP_STATIC_ASSERT(std::is_nothrow_default_constructible::value, ""); +LIBCPP_STATIC_ASSERT(std::is_nothrow_default_constructible< + std::basic_string, test_allocator>>::value, ""); +LIBCPP_STATIC_ASSERT(!std::is_nothrow_default_constructible< + std::basic_string, limited_allocator>>::value, ""); +#endif + +bool test() { + std::string str; + assert(str.empty()); + + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); +#endif + + return 0; +} diff --git a/libcxx/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp +++ /dev/null @@ -1,40 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03 - -// - -// basic_string() -// noexcept(is_nothrow_default_constructible::value); - -// This tests a conforming extension - -#include -#include - -#include "test_macros.h" -#include "test_allocator.h" - -int main(int, char**) -{ - { - typedef std::string C; - static_assert(std::is_nothrow_default_constructible::value, ""); - } - { - typedef std::basic_string, test_allocator> C; - static_assert(std::is_nothrow_default_constructible::value, ""); - } - { - typedef std::basic_string, limited_allocator> C; - static_assert(!std::is_nothrow_default_constructible::value, ""); - } - - return 0; -} diff --git a/libcxx/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp rename from libcxx/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp rename to libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp @@ -34,22 +34,30 @@ std::wstring ws; #endif +static_assert(std::is_nothrow_destructible::value, ""); +static_assert(std::is_nothrow_destructible< + std::basic_string, test_allocator>>::value, ""); +LIBCPP_STATIC_ASSERT(!std::is_nothrow_destructible< + std::basic_string, throwing_alloc>>::value, ""); + +bool test() { + test_allocator_statistics alloc_stats; + { + std::basic_string, test_allocator> str2((test_allocator(&alloc_stats))); + str2 = "long long string so no SSO"; + assert(alloc_stats.alloc_count == 1); + } + assert(alloc_stats.alloc_count == 0); + + return true; +} + int main(int, char**) { - { - typedef std::string C; - static_assert(std::is_nothrow_destructible::value, ""); - } - { - typedef std::basic_string, test_allocator> C; - static_assert(std::is_nothrow_destructible::value, ""); - } -#if defined(_LIBCPP_VERSION) - { - typedef std::basic_string, throwing_alloc> C; - static_assert(!std::is_nothrow_destructible::value, ""); - } -#endif // _LIBCPP_VERSION + test(); +#if TEST_STD_VER > 17 + // static_assert(test()); +#endif return 0; }