Upload upstream chromium 69.0.3497
[platform/framework/web/chromium-efl.git] / base / optional_unittest.nc
1 // Copyright 2018 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 // This is a "No Compile Test" suite.
6 // http://dev.chromium.org/developers/testing/no-compile-tests
7
8 #include <type_traits>
9
10 #include "base/optional.h"
11
12 namespace base {
13
14 #if defined(NCTEST_EXPLICIT_CONVERTING_COPY_CONSTRUCTOR)  // [r"fatal error: no matching function for call to object of type"]
15
16 // Optional<T>(const Optional<U>& arg) constructor is marked explicit if
17 // T is not convertible from "const U&".
18 void WontCompile() {
19   struct Test {
20     // Declares as explicit so that Test is still constructible from int,
21     // but not convertible.
22     explicit Test(int a) {}
23   };
24
25   static_assert(!std::is_convertible<const int&, Test>::value,
26                 "const int& to Test is convertible");
27   const Optional<int> arg(in_place, 1);
28   ([](Optional<Test> param) {})(arg);
29 }
30
31 #elif defined(NCTEST_EXPLICIT_CONVERTING_MOVE_CONSTRUCTOR)  // [r"fatal error: no matching function for call to object of type"]
32
33 // Optional<T>(Optional<U>&& arg) constructor is marked explicit if
34 // T is not convertible from "U&&".
35 void WontCompile() {
36   struct Test {
37     // Declares as explicit so that Test is still constructible from int,
38     // but not convertible.
39     explicit Test(int a) {}
40   };
41
42   static_assert(!std::is_convertible<int&&, Test>::value,
43                 "int&& to Test is convertible");
44   ([](Optional<Test> param) {})(Optional<int>(in_place, 1));
45 }
46
47 #elif defined(NCTEST_EXPLICIT_VALUE_FORWARD_CONSTRUCTOR)  // [r"fatal error: no matching function for call to object of type"]
48
49 // Optional<T>(U&&) constructor is marked explicit if T is not convertible
50 // from U&&.
51 void WontCompile() {
52   struct Test {
53     // Declares as explicit so that Test is still constructible from int,
54     // but not convertible.
55     explicit Test(int a) {}
56   };
57
58   static_assert(!std::is_convertible<int&&, Test>::value,
59                 "int&& to Test is convertible");
60   ([](Optional<Test> param) {})(1);
61 }
62
63 #endif
64
65 }  // namespace base