| 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-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14) |
| 10 | |
| 11 | // XFAIL: FROZEN-CXX03-HEADERS-FIXME |
| 12 | |
| 13 | // <string_view> |
| 14 | // ... manipulating sequences of any non-array trivial standard-layout types. |
| 15 | |
| 16 | #include <string> |
| 17 | #include <type_traits> |
| 18 | #include "../basic.string/test_traits.h" |
| 19 | |
| 20 | struct NotTriviallyCopyable { |
| 21 | int value; |
| 22 | NotTriviallyCopyable& operator=(const NotTriviallyCopyable& other) { |
| 23 | value = other.value; |
| 24 | return *this; |
| 25 | } |
| 26 | }; |
| 27 | |
| 28 | struct NotTriviallyDefaultConstructible { |
| 29 | NotTriviallyDefaultConstructible() : value(3) {} |
| 30 | int value; |
| 31 | }; |
| 32 | |
| 33 | struct NotStandardLayout { |
| 34 | public: |
| 35 | NotStandardLayout() : one(1), two(2) {} |
| 36 | int sum() const { return one + two; } // silences "unused field 'two' warning" |
| 37 | int one; |
| 38 | |
| 39 | private: |
| 40 | int two; |
| 41 | }; |
| 42 | |
| 43 | int main(int, char**) { |
| 44 | { |
| 45 | // array |
| 46 | typedef char C[3]; |
| 47 | static_assert(std::is_array<C>::value, "" ); |
| 48 | std::basic_string_view<C, test_traits<C> > sv; |
| 49 | // expected-error-re@string_view:* {{static assertion failed{{.*}}Character type of basic_string_view must not be an array}} |
| 50 | } |
| 51 | |
| 52 | { |
| 53 | // not trivially copyable |
| 54 | static_assert(!std::is_trivially_copyable<NotTriviallyCopyable>::value, "" ); |
| 55 | std::basic_string_view<NotTriviallyCopyable, test_traits<NotTriviallyCopyable> > s; |
| 56 | // expected-error-re@*:* {{static assertion failed{{.*}}Character type of basic_string_view must be trivially copyable}} |
| 57 | } |
| 58 | |
| 59 | { |
| 60 | // not trivially default constructible |
| 61 | static_assert(!std::is_trivially_default_constructible<NotTriviallyDefaultConstructible>::value, "" ); |
| 62 | std::basic_string_view<NotTriviallyDefaultConstructible, test_traits<NotTriviallyDefaultConstructible> > sv; |
| 63 | // expected-error-re@string_view:* {{static assertion failed{{.*}}Character type of basic_string_view must be trivially default constructible}} |
| 64 | } |
| 65 | |
| 66 | { |
| 67 | // not standard layout |
| 68 | static_assert(!std::is_standard_layout<NotStandardLayout>::value, "" ); |
| 69 | std::basic_string_view<NotStandardLayout, test_traits<NotStandardLayout> > sv; |
| 70 | // expected-error-re@string_view:* {{static assertion failed{{.*}}Character type of basic_string_view must be standard-layout}} |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |