Marshall Clow | 4a6f3c4 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Marshall Clow | 4a6f3c4 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 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 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 29 | int main(int, char**) |
Marshall Clow | 4a6f3c4 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 30 | { |
| 31 | { |
| 32 | // array |
| 33 | typedef char C[3]; |
| 34 | static_assert(std::is_array<C>::value, ""); |
| 35 | std::basic_string<C, test_traits<C> > s; |
| 36 | // expected-error-re@string:* {{static_assert failed{{.*}} "Character type of basic_string must not be an array"}} |
| 37 | } |
| 38 | |
| 39 | { |
| 40 | // not trivial |
| 41 | static_assert(!std::is_trivial<NotTrivial>::value, ""); |
| 42 | std::basic_string<NotTrivial, test_traits<NotTrivial> > s; |
| 43 | // expected-error-re@string:* {{static_assert failed{{.*}} "Character type of basic_string must be trivial"}} |
| 44 | } |
| 45 | |
| 46 | { |
| 47 | // not standard layout |
| 48 | static_assert(!std::is_standard_layout<NotStandardLayout>::value, ""); |
| 49 | std::basic_string<NotStandardLayout, test_traits<NotStandardLayout> > s; |
| 50 | // expected-error-re@string:* {{static_assert failed{{.*}} "Character type of basic_string must be standard-layout"}} |
| 51 | } |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 52 | |
| 53 | return 0; |
Marshall Clow | 4a6f3c4 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 54 | } |