// 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 #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(const Optional& 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::value, "const int& to Test is convertible"); const Optional arg(in_place, 1); ([](Optional param) {})(arg); } #elif defined(NCTEST_EXPLICIT_CONVERTING_MOVE_CONSTRUCTOR) // [r"fatal error: no matching function for call to object of type"] // Optional(Optional&& 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::value, "int&& to Test is convertible"); ([](Optional param) {})(Optional(in_place, 1)); } #elif defined(NCTEST_EXPLICIT_VALUE_FORWARD_CONSTRUCTOR) // [r"fatal error: no matching function for call to object of type"] // Optional(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::value, "int&& to Test is convertible"); ([](Optional param) {})(1); } #endif } // namespace base