mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 03:32:35 +08:00

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@362252 91177308-0d34-0410-b5e6-96231b3b80d8
68 lines
1.4 KiB
C++
68 lines
1.4 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <functional>
|
|
|
|
// class function<R(ArgTypes...)>
|
|
|
|
// template<class F> function(F);
|
|
|
|
// Allow incomplete argument types in the __is_callable check
|
|
|
|
#include <functional>
|
|
#include <cassert>
|
|
|
|
#include "test_macros.h"
|
|
|
|
struct X{
|
|
typedef std::function<void(X&)> callback_type;
|
|
virtual ~X() {}
|
|
private:
|
|
callback_type _cb;
|
|
};
|
|
|
|
struct IncompleteReturnType {
|
|
std::function<IncompleteReturnType ()> fn;
|
|
};
|
|
|
|
|
|
int called = 0;
|
|
IncompleteReturnType test_fn() {
|
|
++called;
|
|
IncompleteReturnType I;
|
|
return I;
|
|
}
|
|
|
|
// See llvm.org/PR34298
|
|
void test_pr34298()
|
|
{
|
|
static_assert(std::is_copy_constructible<IncompleteReturnType>::value, "");
|
|
static_assert(std::is_copy_assignable<IncompleteReturnType>::value, "");
|
|
{
|
|
IncompleteReturnType X;
|
|
X.fn = test_fn;
|
|
const IncompleteReturnType& CX = X;
|
|
IncompleteReturnType X2 = CX;
|
|
assert(X2.fn);
|
|
assert(called == 0);
|
|
X2.fn();
|
|
assert(called == 1);
|
|
}
|
|
{
|
|
IncompleteReturnType Empty;
|
|
IncompleteReturnType X2 = Empty;
|
|
assert(!X2.fn);
|
|
}
|
|
}
|
|
|
|
int main(int, char**) {
|
|
test_pr34298();
|
|
|
|
return 0;
|
|
}
|