1*67e74705SXin Li // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -fcxx-exceptions %s 2*67e74705SXin Li 3*67e74705SXin Li void fn() = default; // expected-error {{only special member}} 4*67e74705SXin Li struct foo { 5*67e74705SXin Li void fn() = default; // expected-error {{only special member}} 6*67e74705SXin Li 7*67e74705SXin Li foo() = default; 8*67e74705SXin Li foo(const foo&) = default; 9*67e74705SXin Li foo(foo&&) = default; 10*67e74705SXin Li foo& operator = (const foo&) = default; 11*67e74705SXin Li foo& operator = (foo&&) = default; 12*67e74705SXin Li ~foo() = default; 13*67e74705SXin Li }; 14*67e74705SXin Li 15*67e74705SXin Li struct bar { 16*67e74705SXin Li bar(); 17*67e74705SXin Li bar(const bar&); 18*67e74705SXin Li bar(bar&&); 19*67e74705SXin Li bar& operator = (const bar&); 20*67e74705SXin Li bar& operator = (bar&&); 21*67e74705SXin Li ~bar(); 22*67e74705SXin Li }; 23*67e74705SXin Li 24*67e74705SXin Li bar::bar() = default; 25*67e74705SXin Li bar::bar(const bar&) = default; 26*67e74705SXin Li bar::bar(bar&&) = default; 27*67e74705SXin Li bar& bar::operator = (const bar&) = default; 28*67e74705SXin Li bar& bar::operator = (bar&&) = default; 29*67e74705SXin Li bar::~bar() = default; 30*67e74705SXin Li 31*67e74705SXin Li static_assert(__is_trivial(foo), "foo should be trivial"); 32*67e74705SXin Li 33*67e74705SXin Li static_assert(!__has_trivial_destructor(bar), "bar's destructor isn't trivial"); 34*67e74705SXin Li static_assert(!__has_trivial_constructor(bar), 35*67e74705SXin Li "bar's default constructor isn't trivial"); 36*67e74705SXin Li static_assert(!__has_trivial_copy(bar), "bar has no trivial copy"); 37*67e74705SXin Li static_assert(!__has_trivial_assign(bar), "bar has no trivial assign"); 38*67e74705SXin Li tester()39*67e74705SXin Livoid tester() { 40*67e74705SXin Li foo f, g(f); 41*67e74705SXin Li bar b, c(b); 42*67e74705SXin Li f = g; 43*67e74705SXin Li b = c; 44*67e74705SXin Li } 45*67e74705SXin Li 46*67e74705SXin Li template<typename T> struct S : T { 47*67e74705SXin Li constexpr S() = default; 48*67e74705SXin Li constexpr S(const S&) = default; 49*67e74705SXin Li constexpr S(S&&) = default; 50*67e74705SXin Li }; litlit51*67e74705SXin Listruct lit { constexpr lit() {} }; 52*67e74705SXin Li S<lit> s_lit; // ok 53*67e74705SXin Li S<bar> s_bar; // ok 54*67e74705SXin Li 55*67e74705SXin Li struct Friends { 56*67e74705SXin Li friend S<bar>::S(); 57*67e74705SXin Li friend S<bar>::S(const S&); 58*67e74705SXin Li friend S<bar>::S(S&&); 59*67e74705SXin Li }; 60*67e74705SXin Li 61*67e74705SXin Li namespace DefaultedFnExceptionSpec { 62*67e74705SXin Li // DR1330: The exception-specification of an implicitly-declared special 63*67e74705SXin Li // member function is evaluated as needed. 64*67e74705SXin Li template<typename T> T &&declval(); 65*67e74705SXin Li template<typename T> struct pair { 66*67e74705SXin Li pair(const pair&) noexcept(noexcept(T(declval<T>()))); 67*67e74705SXin Li }; 68*67e74705SXin Li 69*67e74705SXin Li struct Y; 70*67e74705SXin Li struct X { X(); X(const Y&); }; 71*67e74705SXin Li struct Y { pair<X> p; }; 72*67e74705SXin Li 73*67e74705SXin Li template<typename T> 74*67e74705SXin Li struct A { 75*67e74705SXin Li pair<T> p; 76*67e74705SXin Li }; 77*67e74705SXin Li struct B { 78*67e74705SXin Li B(); 79*67e74705SXin Li B(const A<B>&); 80*67e74705SXin Li }; 81*67e74705SXin Li 82*67e74705SXin Li // Don't crash here. f()83*67e74705SXin Li void f() { 84*67e74705SXin Li X x = X(); 85*67e74705SXin Li (void)noexcept(B(declval<B>())); 86*67e74705SXin Li } 87*67e74705SXin Li 88*67e74705SXin Li template<typename T> 89*67e74705SXin Li struct Error { 90*67e74705SXin Li // FIXME: Type canonicalization causes all the errors to point at the first 91*67e74705SXin Li // declaration which has the type 'void () noexcept (T::error)'. We should 92*67e74705SXin Li // get one error for 'Error<int>::Error()' and one for 'Error<int>::~Error()'. 93*67e74705SXin Li void f() noexcept(T::error); // expected-error 2{{has no members}} 94*67e74705SXin Li 95*67e74705SXin Li Error() noexcept(T::error); 96*67e74705SXin Li Error(const Error&) noexcept(T::error); 97*67e74705SXin Li Error(Error&&) noexcept(T::error); 98*67e74705SXin Li Error &operator=(const Error&) noexcept(T::error); 99*67e74705SXin Li Error &operator=(Error&&) noexcept(T::error); 100*67e74705SXin Li ~Error() noexcept(T::error); 101*67e74705SXin Li }; 102*67e74705SXin Li 103*67e74705SXin Li struct DelayImplicit { 104*67e74705SXin Li Error<int> e; 105*67e74705SXin Li }; 106*67e74705SXin Li 107*67e74705SXin Li // Don't instantiate the exception specification here. 108*67e74705SXin Li void test1(decltype(declval<DelayImplicit>() = DelayImplicit(DelayImplicit()))); 109*67e74705SXin Li void test2(decltype(declval<DelayImplicit>() = declval<const DelayImplicit>())); 110*67e74705SXin Li void test3(decltype(DelayImplicit(declval<const DelayImplicit>()))); 111*67e74705SXin Li 112*67e74705SXin Li // Any odr-use causes the exception specification to be evaluated. 113*67e74705SXin Li struct OdrUse { // \ 114*67e74705SXin Li expected-note {{instantiation of exception specification for 'Error'}} \ 115*67e74705SXin Li expected-note {{instantiation of exception specification for '~Error'}} 116*67e74705SXin Li Error<int> e; 117*67e74705SXin Li }; 118*67e74705SXin Li OdrUse use; // expected-note {{implicit default constructor for 'DefaultedFnExceptionSpec::OdrUse' first required here}} 119*67e74705SXin Li } 120*67e74705SXin Li 121*67e74705SXin Li namespace PR13527 { 122*67e74705SXin Li struct X { 123*67e74705SXin Li X() = delete; // expected-note {{here}} 124*67e74705SXin Li X(const X&) = delete; // expected-note {{here}} 125*67e74705SXin Li X(X&&) = delete; // expected-note {{here}} 126*67e74705SXin Li X &operator=(const X&) = delete; // expected-note {{here}} 127*67e74705SXin Li X &operator=(X&&) = delete; // expected-note {{here}} 128*67e74705SXin Li ~X() = delete; // expected-note {{here}} 129*67e74705SXin Li }; 130*67e74705SXin Li X::X() = default; // expected-error {{redefinition}} 131*67e74705SXin Li X::X(const X&) = default; // expected-error {{redefinition}} 132*67e74705SXin Li X::X(X&&) = default; // expected-error {{redefinition}} 133*67e74705SXin Li X &X::operator=(const X&) = default; // expected-error {{redefinition}} 134*67e74705SXin Li X &X::operator=(X&&) = default; // expected-error {{redefinition}} 135*67e74705SXin Li X::~X() = default; // expected-error {{redefinition}} 136*67e74705SXin Li 137*67e74705SXin Li struct Y { 138*67e74705SXin Li Y() = default; 139*67e74705SXin Li Y(const Y&) = default; 140*67e74705SXin Li Y(Y&&) = default; 141*67e74705SXin Li Y &operator=(const Y&) = default; 142*67e74705SXin Li Y &operator=(Y&&) = default; 143*67e74705SXin Li ~Y() = default; 144*67e74705SXin Li }; 145*67e74705SXin Li Y::Y() = default; // expected-error {{definition of explicitly defaulted}} 146*67e74705SXin Li Y::Y(const Y&) = default; // expected-error {{definition of explicitly defaulted}} 147*67e74705SXin Li Y::Y(Y&&) = default; // expected-error {{definition of explicitly defaulted}} 148*67e74705SXin Li Y &Y::operator=(const Y&) = default; // expected-error {{definition of explicitly defaulted}} 149*67e74705SXin Li Y &Y::operator=(Y&&) = default; // expected-error {{definition of explicitly defaulted}} 150*67e74705SXin Li Y::~Y() = default; // expected-error {{definition of explicitly defaulted}} 151*67e74705SXin Li } 152*67e74705SXin Li 153*67e74705SXin Li namespace PR27699 { 154*67e74705SXin Li struct X { 155*67e74705SXin Li X(); 156*67e74705SXin Li }; 157*67e74705SXin Li X::X() = default; // expected-note {{here}} 158*67e74705SXin Li X::X() = default; // expected-error {{redefinition of 'X'}} 159*67e74705SXin Li } 160*67e74705SXin Li 161*67e74705SXin Li namespace PR14577 { 162*67e74705SXin Li template<typename T> 163*67e74705SXin Li struct Outer { 164*67e74705SXin Li template<typename U> 165*67e74705SXin Li struct Inner1 { 166*67e74705SXin Li ~Inner1(); 167*67e74705SXin Li }; 168*67e74705SXin Li 169*67e74705SXin Li template<typename U> 170*67e74705SXin Li struct Inner2 { 171*67e74705SXin Li ~Inner2(); 172*67e74705SXin Li }; 173*67e74705SXin Li }; 174*67e74705SXin Li 175*67e74705SXin Li template<typename T> 176*67e74705SXin Li 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}} 177*67e74705SXin Li 178*67e74705SXin Li template<typename T> 179*67e74705SXin Li 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}} 180*67e74705SXin Li } 181*67e74705SXin Li 182*67e74705SXin Li extern "C" { 183*67e74705SXin Li template<typename _Tp> // expected-error {{templates must have C++ linkage}} 184*67e74705SXin Li void PR13573(const _Tp&) = delete; 185*67e74705SXin Li } 186*67e74705SXin Li 187*67e74705SXin Li namespace PR15597 { 188*67e74705SXin Li template<typename T> struct A { 189*67e74705SXin Li A() noexcept(true) = default; 190*67e74705SXin Li ~A() noexcept(true) = default; 191*67e74705SXin Li }; 192*67e74705SXin Li template<typename T> struct B { 193*67e74705SXin Li B() noexcept(false) = default; // expected-error {{does not match the calculated one}} 194*67e74705SXin Li ~B() noexcept(false) = default; // expected-error {{does not match the calculated one}} 195*67e74705SXin Li }; 196*67e74705SXin Li A<int> a; 197*67e74705SXin Li B<int> b; // expected-note {{here}} 198*67e74705SXin Li } 199*67e74705SXin Li 200*67e74705SXin Li namespace PR27941 { 201*67e74705SXin Li struct ExplicitBool { 202*67e74705SXin Li ExplicitBool &operator=(bool) = default; // expected-error{{only special member functions may be defaulted}} 203*67e74705SXin Li int member; 204*67e74705SXin Li }; 205*67e74705SXin Li fn()206*67e74705SXin Liint fn() { 207*67e74705SXin Li ExplicitBool t; 208*67e74705SXin Li t = true; 209*67e74705SXin Li } 210*67e74705SXin Li } 211