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 // <iterator>
10 
11 // class istream_iterator
12 
13 // istream_iterator(); // constexpr since C++11
14 // C++17 says: If is_trivially_default_constructible_v<T> is true, then this
15 //    constructor is a constexpr constructor.
16 
17 #include <iterator>
18 #include <cassert>
19 #include <string>
20 
21 #include "test_macros.h"
22 
23 struct S { S(); }; // not constexpr
24 
25 #if TEST_STD_VER > 14
26 template <typename T, bool isTrivial = std::is_trivially_default_constructible_v<T>>
27 struct test_trivial {
operator ()test_trivial28 void operator ()() const {
29     constexpr std::istream_iterator<T> it;
30     (void)it;
31     }
32 };
33 
34 template <typename T>
35 struct test_trivial<T, false> {
operator ()test_trivial36 void operator ()() const {}
37 };
38 #endif
39 
40 
main(int,char **)41 int main(int, char**) {
42     {
43     typedef std::istream_iterator<int> T;
44     T it;
45     assert(it == T());
46 #if TEST_STD_VER >= 11
47     constexpr T it2;
48     (void)it2;
49 #endif
50     }
51 
52 #if TEST_STD_VER > 14
53     test_trivial<int>()();
54     test_trivial<char>()();
55     test_trivial<double>()();
56     test_trivial<S>()();
57     test_trivial<std::string>()();
58 #endif
59 
60   return 0;
61 }
62