blob: bebcfd87d965b47faa3f73ea45cd2a53f9b0e4fb [file] [log] [blame]
Vitaly Bukacbed2062015-08-17 12:54:05 -07001// Copyright (c) 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/move.h"
6
Vitaly Buka8750b272015-08-18 18:39:08 -07007#include <gtest/gtest.h>
Vitaly Bukacbed2062015-08-17 12:54:05 -07008
9namespace {
10
11class MoveOnly {
12 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(MoveOnly)
13
14 public:
15 MoveOnly() {}
16
17 MoveOnly(MoveOnly&& other) {}
18 MoveOnly& operator=(MoveOnly&& other) { return *this; }
19};
20
21class Container {
22 public:
23 Container() = default;
24 Container(const Container& other) = default;
25 Container& operator=(const Container& other) = default;
26
27 Container(Container&& other) { value_ = other.value_.Pass(); }
28
29 Container& operator=(Container&& other) {
30 value_ = other.value_.Pass();
31 return *this;
32 }
33
34 private:
35 MoveOnly value_;
36};
37
38Container GetContainerRvalue() {
39 Container x;
40 return x;
41}
42
43TEST(MoveTest, CopyableContainerCanBeMoved) {
44 // Container should be move-constructible and move-assignable.
45 Container y = GetContainerRvalue();
46 y = GetContainerRvalue();
47}
48
49} // namespace