cxx0x-defaulted-functions.cpp [plain text]
void fn() = default; struct foo {
void fn() = default;
foo() = default;
foo(const foo&) = default;
foo(foo&&) = default;
foo& operator = (const foo&) = default;
foo& operator = (foo&&) = default;
~foo() = default;
};
struct bar {
bar();
bar(const bar&);
bar(bar&&);
bar& operator = (const bar&);
bar& operator = (bar&&);
~bar();
};
bar::bar() = default;
bar::bar(const bar&) = default;
bar::bar(bar&&) = default;
bar& bar::operator = (const bar&) = default;
bar& bar::operator = (bar&&) = default;
bar::~bar() = default;
static_assert(__is_trivial(foo), "foo should be trivial");
static_assert(!__has_trivial_destructor(bar), "bar's destructor isn't trivial");
static_assert(!__has_trivial_constructor(bar),
"bar's default constructor isn't trivial");
static_assert(!__has_trivial_copy(bar), "bar has no trivial copy");
static_assert(!__has_trivial_assign(bar), "bar has no trivial assign");
void tester() {
foo f, g(f);
bar b, c(b);
f = g;
b = c;
}
template<typename T> struct S : T {
constexpr S() = default;
constexpr S(const S&) = default;
constexpr S(S&&) = default;
};
struct lit { constexpr lit() {} };
S<lit> s_lit; S<bar> s_bar;
struct Friends {
friend S<bar>::S();
friend S<bar>::S(const S&);
friend S<bar>::S(S&&);
};
namespace DefaultedFnExceptionSpec {
template<typename T> T &&declval();
template<typename T> struct pair {
pair(const pair&) noexcept(noexcept(T(declval<T>())));
};
struct Y;
struct X { X(); X(const Y&); };
struct Y { pair<X> p; };
template<typename T>
struct A {
pair<T> p;
};
struct B {
B();
B(const A<B>&);
};
void f() {
X x = X();
(void)noexcept(B(declval<B>()));
}
template<typename T>
struct Error {
void f() noexcept(T::error);
Error() noexcept(T::error);
Error(const Error&) noexcept(T::error);
Error(Error&&) noexcept(T::error);
Error &operator=(const Error&) noexcept(T::error);
Error &operator=(Error&&) noexcept(T::error);
~Error() noexcept(T::error);
};
struct DelayImplicit {
Error<int> e;
};
void test1(decltype(declval<DelayImplicit>() = DelayImplicit(DelayImplicit())));
void test2(decltype(declval<DelayImplicit>() = declval<const DelayImplicit>()));
void test3(decltype(DelayImplicit(declval<const DelayImplicit>())));
struct OdrUse { expected-note {{instantiation of exception specification for 'Error'}} \
expected-note {{instantiation of exception specification for '~Error'}}
Error<int> e;
};
OdrUse use; }
namespace PR13527 {
struct X {
X() = delete; X(const X&) = delete; X(X&&) = delete; X &operator=(const X&) = delete; X &operator=(X&&) = delete; ~X() = delete; };
X::X() = default; X::X(const X&) = default; X::X(X&&) = default; X &X::operator=(const X&) = default; X &X::operator=(X&&) = default; X::~X() = default;
struct Y {
Y() = default;
Y(const Y&) = default;
Y(Y&&) = default;
Y &operator=(const Y&) = default;
Y &operator=(Y&&) = default;
~Y() = default;
};
Y::Y() = default; Y::Y(const Y&) = default; Y::Y(Y&&) = default; Y &Y::operator=(const Y&) = default; Y &Y::operator=(Y&&) = default; Y::~Y() = default; }