• 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_move_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     constexpr S(const S  &rhs) : v_(rhs.v_) {} // not trivially moveable
SS27     constexpr S(const S &&rhs) : v_(rhs.v_) {} // not trivially moveable
28     int v_;
29     };
30 
31 
main()32 int main()
33 {
34     static_assert (!std::is_trivially_move_constructible_v<S>, "" );
35     constexpr std::optional<S> o1;
36     constexpr std::optional<S> o2 = std::move(o1);  // not constexpr
37 }
38