1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -fcxx-exceptions %s
3 void fn() = default; // expected-error {{only special member}}
5 void fn() = default; // expected-error {{only special member}}
8 foo(const foo&) = default;
10 foo& operator = (const foo&) = default;
11 foo& operator = (foo&&) = default;
19 bar& operator = (const bar&);
20 bar& operator = (bar&&);
25 bar::bar(const bar&) = default;
26 bar::bar(bar&&) = default;
27 bar& bar::operator = (const bar&) = default;
28 bar& bar::operator = (bar&&) = default;
29 bar::~bar() = default;
31 static_assert(__is_trivial(foo), "foo should be trivial");
33 static_assert(!__has_trivial_destructor(bar), "bar's destructor isn't trivial");
34 static_assert(!__has_trivial_constructor(bar),
35 "bar's default constructor isn't trivial");
36 static_assert(!__has_trivial_copy(bar), "bar has no trivial copy");
37 static_assert(!__has_trivial_assign(bar), "bar has no trivial assign");
46 template<typename T> struct S : T {
47 constexpr S() = default;
48 constexpr S(const S&) = default;
49 constexpr S(S&&) = default;
51 struct lit { constexpr lit() {} };
57 friend S<bar>::S(const S&);
58 friend S<bar>::S(S&&);
61 namespace DefaultedFnExceptionSpec {
62 // DR1330: The exception-specification of an implicitly-declared special
63 // member function is evaluated as needed.
64 template<typename T> T &&declval();
65 template<typename T> struct pair {
66 pair(const pair&) noexcept(noexcept(T(declval<T>())));
70 struct X { X(); X(const Y&); };
71 struct Y { pair<X> p; };
85 (void)noexcept(B(declval<B>()));
90 // FIXME: Type canonicalization causes all the errors to point at the first
91 // declaration which has the type 'void () noexcept (T::error)'. We should
92 // get one error for 'Error<int>::Error()' and one for 'Error<int>::~Error()'.
93 void f() noexcept(T::error); // expected-error 2{{has no members}}
95 Error() noexcept(T::error);
96 Error(const Error&) noexcept(T::error);
97 Error(Error&&) noexcept(T::error);
98 Error &operator=(const Error&) noexcept(T::error);
99 Error &operator=(Error&&) noexcept(T::error);
100 ~Error() noexcept(T::error);
103 struct DelayImplicit {
107 // Don't instantiate the exception specification here.
108 void test1(decltype(declval<DelayImplicit>() = DelayImplicit(DelayImplicit())));
109 void test2(decltype(declval<DelayImplicit>() = declval<const DelayImplicit>()));
110 void test3(decltype(DelayImplicit(declval<const DelayImplicit>())));
112 // Any odr-use causes the exception specification to be evaluated.
114 expected-note {{instantiation of exception specification for 'Error'}} \
115 expected-note {{instantiation of exception specification for '~Error'}}
118 OdrUse use; // expected-note {{implicit default constructor for 'DefaultedFnExceptionSpec::OdrUse' first required here}}
123 X() = delete; // expected-note {{here}}
124 X(const X&) = delete; // expected-note {{here}}
125 X(X&&) = delete; // expected-note {{here}}
126 X &operator=(const X&) = delete; // expected-note {{here}}
127 X &operator=(X&&) = delete; // expected-note {{here}}
128 ~X() = delete; // expected-note {{here}}
130 X::X() = default; // expected-error {{redefinition}}
131 X::X(const X&) = default; // expected-error {{redefinition}}
132 X::X(X&&) = default; // expected-error {{redefinition}}
133 X &X::operator=(const X&) = default; // expected-error {{redefinition}}
134 X &X::operator=(X&&) = default; // expected-error {{redefinition}}
135 X::~X() = default; // expected-error {{redefinition}}
139 Y(const Y&) = default;
141 Y &operator=(const Y&) = default;
142 Y &operator=(Y&&) = default;
145 Y::Y() = default; // expected-error {{definition of explicitly defaulted}}
146 Y::Y(const Y&) = default; // expected-error {{definition of explicitly defaulted}}
147 Y::Y(Y&&) = default; // expected-error {{definition of explicitly defaulted}}
148 Y &Y::operator=(const Y&) = default; // expected-error {{definition of explicitly defaulted}}
149 Y &Y::operator=(Y&&) = default; // expected-error {{definition of explicitly defaulted}}
150 Y::~Y() = default; // expected-error {{definition of explicitly defaulted}}
168 Outer<T>::Inner1<T>::~Inner1() = delete; // expected-error {{nested name specifier 'Outer<T>::Inner1<T>::' for declaration does not refer into a class, class template or class template partial specialization}} expected-error {{only functions can have deleted definitions}}
171 Outer<T>::Inner2<T>::~Inner2() = default; // expected-error {{nested name specifier 'Outer<T>::Inner2<T>::' for declaration does not refer into a class, class template or class template partial specialization}} expected-error {{only special member functions may be defaulted}}
175 template<typename _Tp> // expected-error {{templates must have C++ linkage}}
176 void PR13573(const _Tp&) = delete;
180 template<typename T> struct A {
181 A() noexcept(true) = default;
182 ~A() noexcept(true) = default;
184 template<typename T> struct B {
185 B() noexcept(false) = default; // expected-error {{does not match the calculated one}}
186 ~B() noexcept(false) = default; // expected-error {{does not match the calculated one}}
189 B<int> b; // expected-note {{here}}