xref: /aosp_15_r20/external/libcxx/test/std/strings/basic.string/char.bad.fail.cpp (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
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>
11 //   ... manipulating sequences of any non-array trivial standard-layout types.
12 
13 #include <string>
14 #include "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<C, test_traits<C> > s;
37 //  expected-error-re@string:* {{static_assert failed{{.*}} "Character type of basic_string must not be an array"}}
38     }
39 
40     {
41 //  not trivial
42     static_assert(!std::is_trivial<NotTrivial>::value, "");
43     std::basic_string<NotTrivial, test_traits<NotTrivial> > s;
44 //  expected-error-re@string:* {{static_assert failed{{.*}} "Character type of basic_string must be trivial"}}
45     }
46 
47     {
48 //  not standard layout
49     static_assert(!std::is_standard_layout<NotStandardLayout>::value, "");
50     std::basic_string<NotStandardLayout, test_traits<NotStandardLayout> > s;
51 //  expected-error-re@string:* {{static_assert failed{{.*}} "Character type of basic_string must be standard-layout"}}
52     }
53 }
54