[wpiutil] Vendor llvm and update to 13.0.0 (#4224)

This commit is contained in:
PJ Reiniger
2022-05-20 18:59:53 -04:00
committed by GitHub
parent 5aa67f56e6
commit c3b223ce60
106 changed files with 16897 additions and 1895 deletions

View File

@@ -1,9 +1,8 @@
//===- FunctionExtrasTest.cpp - Unit tests for function type erasure ------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -11,6 +10,7 @@
#include "gtest/gtest.h"
#include <memory>
#include <type_traits>
using namespace wpi;
@@ -225,4 +225,70 @@ TEST(UniqueFunctionTest, CountForwardingMoves) {
UnmovableF(X);
}
TEST(UniqueFunctionTest, Const) {
// Can assign from const lambda.
unique_function<int(int) const> Plus2 = [X(std::make_unique<int>(2))](int Y) {
return *X + Y;
};
EXPECT_EQ(5, Plus2(3));
// Can call through a const ref.
const auto &Plus2Ref = Plus2;
EXPECT_EQ(5, Plus2Ref(3));
// Can move-construct and assign.
unique_function<int(int) const> Plus2A = std::move(Plus2);
EXPECT_EQ(5, Plus2A(3));
unique_function<int(int) const> Plus2B;
Plus2B = std::move(Plus2A);
EXPECT_EQ(5, Plus2B(3));
// Can convert to non-const function type, but not back.
unique_function<int(int)> Plus2C = std::move(Plus2B);
EXPECT_EQ(5, Plus2C(3));
// Overloaded call operator correctly resolved.
struct ChooseCorrectOverload {
std::string_view operator()() { return "non-const"; }
std::string_view operator()() const { return "const"; }
};
unique_function<std::string_view()> ChooseMutable = ChooseCorrectOverload();
ChooseCorrectOverload A;
EXPECT_EQ("non-const", ChooseMutable());
EXPECT_EQ("non-const", A());
unique_function<std::string_view() const> ChooseConst = ChooseCorrectOverload();
const ChooseCorrectOverload &X = A;
EXPECT_EQ("const", ChooseConst());
EXPECT_EQ("const", X());
}
// Test that overloads on unique_functions are resolved as expected.
std::string returns(std::string_view) { return "not a function"; }
std::string returns(unique_function<double()> F) { return "number"; }
std::string returns(unique_function<std::string_view()> F) { return "string"; }
TEST(UniqueFunctionTest, SFINAE) {
EXPECT_EQ("not a function", returns("boo!"));
EXPECT_EQ("number", returns([] { return 42; }));
EXPECT_EQ("string", returns([] { return "hello"; }));
}
// A forward declared type, and a templated type.
class Incomplete;
template <typename T> class Templated { T A; };
// Check that we can define unique_function that have references to
// incomplete types, even if those types are templated over an
// incomplete type.
TEST(UniqueFunctionTest, IncompleteTypes) {
unique_function<void(Templated<Incomplete> &&)>
IncompleteArgumentRValueReference;
unique_function<void(Templated<Incomplete> &)>
IncompleteArgumentLValueReference;
unique_function<void(Templated<Incomplete> *)> IncompleteArgumentPointer;
unique_function<Templated<Incomplete> &()> IncompleteResultLValueReference;
unique_function<Templated<Incomplete> && ()> IncompleteResultRValueReference2;
unique_function<Templated<Incomplete> *()> IncompleteResultPointer;
}
} // anonymous namespace