default.pass.cpp revision 506f7fcee59ff2c9ec98251b090149f762bb0992
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// <iterator>
11
12// class istream_iterator
13
14// constexpr istream_iterator();
15// C++17 says: If is_trivially_default_constructible_v<T> is true, then this
16//    constructor shall beis a constexpr constructor.
17
18#include <iterator>
19#include <cassert>
20#include <string>
21
22#include "test_macros.h"
23
24struct S { S(); }; // not constexpr
25
26#if TEST_STD_VER > 14
27template <typename T, bool isTrivial = std::is_trivially_default_constructible_v<T>>
28struct test_trivial {
29void operator ()() const {
30    constexpr std::istream_iterator<T> it;
31    }
32};
33
34template <typename T>
35struct test_trivial<T, false> {
36void operator ()() const {}
37};
38#endif
39
40
41int main()
42{
43    {
44    typedef std::istream_iterator<int> T;
45    T it;
46    assert(it == T());
47#if TEST_STD_VER >= 11
48    constexpr T 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