xref: /llvm-project/libcxx/test/std/strings/basic.string/char.bad.verify.cpp (revision 1da311902555e320540cc3082b226d63cf2c200c)
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 // <string>
10 //   ... manipulating sequences of any non-array trivial standard-layout types.
11 
12 #include <string>
13 #include "test_traits.h"
14 
15 struct NotTrivial {
16     NotTrivial() : value(3) {}
17     int value;
18 };
19 
20 struct NotStandardLayout {
21 public:
22     NotStandardLayout() : one(1), two(2) {}
23     int sum() const { return one + two; } // silences "unused field 'two' warning"
24     int one;
25 private:
26     int two;
27 };
28 
29 void f() {
30     {
31         // array
32         typedef char C[3];
33         static_assert(std::is_array<C>::value, "");
34         std::basic_string<C, test_traits<C> > s;
35         // expected-error-re@string:* {{static_assert failed{{.*}}Character type of basic_string must not be an array}}
36     }
37 
38     {
39         // not trivial
40         static_assert(!std::is_trivial<NotTrivial>::value, "");
41         std::basic_string<NotTrivial, test_traits<NotTrivial> > s;
42         // expected-error-re@string:* {{static_assert failed{{.*}}Character type of basic_string must be trivial}}
43     }
44 
45     {
46         // not standard layout
47         static_assert(!std::is_standard_layout<NotStandardLayout>::value, "");
48         std::basic_string<NotStandardLayout, test_traits<NotStandardLayout> > s;
49         // expected-error-re@string:* {{static_assert failed{{.*}}Character type of basic_string must be standard-layout}}
50     }
51 }
52