| 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 | // <random> |
| 10 | |
| 11 | // class seed_seq; |
| 12 | |
| 13 | // template<class RandomAccessIterator> |
| 14 | // void generate(RandomAccessIterator begin, RandomAccessIterator end); |
| 15 | |
| 16 | // Check the following requirement: https://eel.is/c++draft/rand.util.seedseq#7 |
| 17 | // |
| 18 | // Mandates: iterator_traits<RandomAccessIterator>::value_type is an unsigned integer |
| 19 | // type capable of accommodating 32-bit quantities. |
| 20 | |
| 21 | // UNSUPPORTED: c++03 |
| 22 | // REQUIRES: stdlib=libc++ |
| 23 | |
| 24 | #include <random> |
| 25 | #include <climits> |
| 26 | #include <cstdint> |
| 27 | |
| 28 | #include "test_macros.h" |
| 29 | |
| 30 | void f() { |
| 31 | std::seed_seq seq; |
| 32 | |
| 33 | // Not an integral type |
| 34 | { |
| 35 | double* p = nullptr; |
| 36 | seq.generate(p, p); // expected-error-re@*:* {{static assertion failed{{.+}}: [rand.util.seedseq]/7 requires{{.+}}}} |
| 37 | // expected-error@*:* 0+ {{invalid operands to}} |
| 38 | } |
| 39 | |
| 40 | // Not an unsigned type |
| 41 | { |
| 42 | long long* p = nullptr; |
| 43 | seq.generate(p, p); // expected-error-re@*:* {{static assertion failed{{.+}}: [rand.util.seedseq]/7 requires{{.+}}}} |
| 44 | } |
| 45 | |
| 46 | // Not a 32-bit type |
| 47 | { |
| 48 | #if UCHAR_MAX < UINT32_MAX |
| 49 | unsigned char* p = nullptr; |
| 50 | seq.generate(p, p); // expected-error-re@*:* {{static assertion failed{{.+}}: [rand.util.seedseq]/7 requires{{.+}}}} |
| 51 | #endif |
| 52 | } |
| 53 | |
| 54 | // Everything satisfied |
| 55 | { |
| 56 | unsigned long* p = nullptr; |
| 57 | seq.generate(p, p); // no diagnostic |
| 58 | } |
| 59 | } |
| 60 | |