• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 // <optional>
12 
13 // constexpr optional(const optional<T>& rhs);
14 //   If is_trivially_copy_constructible_v<T> is true,
15 //    this constructor shall be a constexpr constructor.
16 
17 #include <optional>
18 #include <type_traits>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 
23 struct S {
SS24     constexpr S()   : v_(0) {}
SS25     S(int v)        : v_(v) {}
SS26     S(const S &rhs) : v_(rhs.v_) {}  // make it not trivially copyable
27     int v_;
28     };
29 
30 
main()31 int main()
32 {
33     static_assert (!std::is_trivially_copy_constructible_v<S>, "" );
34     constexpr std::optional<S> o1;
35     constexpr std::optional<S> o2 = o1;  // not constexpr
36 }
37