brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 49a9087 Raw
73 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310 11// <string>12 13// basic_string<charT,traits,Allocator>&14//   operator=(basic_string<charT,traits,Allocator>&& str); // constexpr since C++2015 16#include <string>17#include <cassert>18 19#include "test_macros.h"20#include "asan_testing.h"21 22TEST_CONSTEXPR_CXX20 bool test() {23  // Test that assignment from {} and {ptr, len} are allowed and are not24  // ambiguous.25  {26    std::string s = "hello world";27    s             = {};28    assert(s.empty());29    LIBCPP_ASSERT(is_string_asan_correct(s));30  }31  {32    std::string s = "hello world";33    s             = {"abc", 2};34    assert(s == "ab");35    LIBCPP_ASSERT(is_string_asan_correct(s));36  }37  {38    std::string s = "hello world";39    s             = {"It'sALongString!NoSSO!qwertyuiop", 30};40    assert(s == "It'sALongString!NoSSO!qwertyui");41    LIBCPP_ASSERT(is_string_asan_correct(s));42  }43  {44    std::string s = "Hello world! Hello world! Hello world! Hello world! Hello world!";45    s             = {"It'sALongString!NoSSO!qwertyuiop", 30};46    assert(s == "It'sALongString!NoSSO!qwertyui");47    LIBCPP_ASSERT(is_string_asan_correct(s));48  }49  {50    std::string s = "Hello world! Hello world! Hello world! Hello world! Hello world!";51    s             = {"abc", 2};52    assert(s == "ab");53    LIBCPP_ASSERT(is_string_asan_correct(s));54  }55  {56    std::string s = "Hello world! Hello world! Hello world! Hello world! Hello world!";57    s             = {"abc", 0};58    assert(s == "");59    LIBCPP_ASSERT(is_string_asan_correct(s));60  }61 62  return true;63}64 65int main(int, char**) {66  test();67#if TEST_STD_VER > 1768  static_assert(test());69#endif70 71  return 0;72}73