libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

ctor.pass.cpp (1242B)


      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 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
     10 
     11 // <chrono>
     12 // class year;
     13 
     14 //                     year() = default;
     15 //  explicit constexpr year(int m) noexcept;
     16 //  explicit constexpr operator int() const noexcept;
     17 
     18 //  Effects: Constructs an object of type year by initializing y_ with y.
     19 //    The value held is unspecified if d is not in the range [0, 255].
     20 
     21 #include <chrono>
     22 #include <type_traits>
     23 #include <cassert>
     24 
     25 #include "test_macros.h"
     26 
     27 int main()
     28 {
     29     using year = std::chrono::year;
     30 
     31     ASSERT_NOEXCEPT(year{});
     32     ASSERT_NOEXCEPT(year(0U));
     33     ASSERT_NOEXCEPT(static_cast<int>(year(0U)));
     34 
     35     constexpr year y0{};
     36     static_assert(static_cast<int>(y0) == 0, "");
     37 
     38     constexpr year y1{1};
     39     static_assert(static_cast<int>(y1) == 1, "");
     40 
     41     for (int i = 0; i <= 2550; i += 7)
     42     {
     43         year year(i);
     44         assert(static_cast<int>(year) == i);
     45     }
     46 }