1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <string_view>
11 //   ... manipulating sequences of any non-array trivial standard-layout types.
12 
13 #include <string>
14 #include "../basic.string/test_traits.h"
15 
16 struct NotTrivial {
NotTrivialNotTrivial17     NotTrivial() : value(3) {}
18     int value;
19 };
20 
21 struct NotStandardLayout {
22 public:
NotStandardLayoutNotStandardLayout23     NotStandardLayout() : one(1), two(2) {}
sumNotStandardLayout24     int sum() const { return one + two; } // silences "unused field 'two' warning"
25     int one;
26 private:
27     int two;
28 };
29 
main()30 int main()
31 {
32     {
33 //  array
34     typedef char C[3];
35     static_assert(std::is_array<C>::value, "");
36     std::basic_string_view<C, test_traits<C> > sv;
37 //  expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must not be an array"}}
38     }
39 
40     {
41 //  not trivial
42     static_assert(!std::is_trivial<NotTrivial>::value, "");
43     std::basic_string_view<NotTrivial, test_traits<NotTrivial> > sv;
44 //  expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be trivial"}}
45     }
46 
47     {
48 //  not standard layout
49     static_assert(!std::is_standard_layout<NotStandardLayout>::value, "");
50     std::basic_string_view<NotStandardLayout, test_traits<NotStandardLayout> > sv;
51 //  expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be standard-layout"}}
52     }
53 }
54