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.
5 // This is a "No Compile Test" suite.
6 // http://dev.chromium.org/developers/testing/no-compile-tests
10 #include "base/optional.h"
14 #if defined(NCTEST_EXPLICIT_CONVERTING_COPY_CONSTRUCTOR) // [r"fatal error: no matching function for call to object of type"]
16 // Optional<T>(const Optional<U>& arg) constructor is marked explicit if
17 // T is not convertible from "const U&".
20 // Declares as explicit so that Test is still constructible from int,
21 // but not convertible.
22 explicit Test(int a) {}
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);
31 #elif defined(NCTEST_EXPLICIT_CONVERTING_MOVE_CONSTRUCTOR) // [r"fatal error: no matching function for call to object of type"]
33 // Optional<T>(Optional<U>&& arg) constructor is marked explicit if
34 // T is not convertible from "U&&".
37 // Declares as explicit so that Test is still constructible from int,
38 // but not convertible.
39 explicit Test(int a) {}
42 static_assert(!std::is_convertible<int&&, Test>::value,
43 "int&& to Test is convertible");
44 ([](Optional<Test> param) {})(Optional<int>(in_place, 1));
47 #elif defined(NCTEST_EXPLICIT_VALUE_FORWARD_CONSTRUCTOR) // [r"fatal error: no matching function for call to object of type"]
49 // Optional<T>(U&&) constructor is marked explicit if T is not convertible
53 // Declares as explicit so that Test is still constructible from int,
54 // but not convertible.
55 explicit Test(int a) {}
58 static_assert(!std::is_convertible<int&&, Test>::value,
59 "int&& to Test is convertible");
60 ([](Optional<Test> param) {})(1);