summaryrefslogtreecommitdiff
path: root/chromium/base/optional_unittest.nc
blob: 62c0196765cb03c736144c0b65143c6d35f656df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is a "No Compile Test" suite.
// http://dev.chromium.org/developers/testing/no-compile-tests

#include <type_traits>

#include "base/optional.h"

namespace base {

#if defined(NCTEST_EXPLICIT_CONVERTING_COPY_CONSTRUCTOR)  // [r"fatal error: no matching function for call to object of type"]

// Optional<T>(const Optional<U>& arg) constructor is marked explicit if
// T is not convertible from "const U&".
void WontCompile() {
  struct Test {
    // Declares as explicit so that Test is still constructible from int,
    // but not convertible.
    explicit Test(int a) {}
  };

  static_assert(!std::is_convertible<const int&, Test>::value,
                "const int& to Test is convertible");
  const Optional<int> arg(in_place, 1);
  ([](Optional<Test> param) {})(arg);
}

#elif defined(NCTEST_EXPLICIT_CONVERTING_MOVE_CONSTRUCTOR)  // [r"fatal error: no matching function for call to object of type"]

// Optional<T>(Optional<U>&& arg) constructor is marked explicit if
// T is not convertible from "U&&".
void WontCompile() {
  struct Test {
    // Declares as explicit so that Test is still constructible from int,
    // but not convertible.
    explicit Test(int a) {}
  };

  static_assert(!std::is_convertible<int&&, Test>::value,
                "int&& to Test is convertible");
  ([](Optional<Test> param) {})(Optional<int>(in_place, 1));
}

#elif defined(NCTEST_EXPLICIT_VALUE_FORWARD_CONSTRUCTOR)  // [r"fatal error: no matching function for call to object of type"]

// Optional<T>(U&&) constructor is marked explicit if T is not convertible
// from U&&.
void WontCompile() {
  struct Test {
    // Declares as explicit so that Test is still constructible from int,
    // but not convertible.
    explicit Test(int a) {}
  };

  static_assert(!std::is_convertible<int&&, Test>::value,
                "int&& to Test is convertible");
  ([](Optional<Test> param) {})(1);
}

#endif

}  // namespace base