1afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 25c478cf2d54157062cd843737324e0d0df03a464Anders Carlsson 33d04336baf091b16e9d8f85b48b82dafd2695874John McCallstruct A { }; 4f961ea5716867b5e426fb2136edd6d1f04c3a7caSean HuntA::A() { } // expected-error {{definition of implicitly declared default constructor}} 55c478cf2d54157062cd843737324e0d0df03a464Anders Carlsson 63d04336baf091b16e9d8f85b48b82dafd2695874John McCallstruct B { }; 75c478cf2d54157062cd843737324e0d0df03a464Anders CarlssonB::B(const B&) { } // expected-error {{definition of implicitly declared copy constructor}} 85c478cf2d54157062cd843737324e0d0df03a464Anders Carlsson 93d04336baf091b16e9d8f85b48b82dafd2695874John McCallstruct C { }; 105c478cf2d54157062cd843737324e0d0df03a464Anders CarlssonC& C::operator=(const C&) { return *this; } // expected-error {{definition of implicitly declared copy assignment operator}} 115c478cf2d54157062cd843737324e0d0df03a464Anders Carlsson 123d04336baf091b16e9d8f85b48b82dafd2695874John McCallstruct D { }; 135c478cf2d54157062cd843737324e0d0df03a464Anders CarlssonD::~D() { } // expected-error {{definition of implicitly declared destructor}} 145c478cf2d54157062cd843737324e0d0df03a464Anders Carlsson 156275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor// Make sure that the special member functions are introduced for 166275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor// name-lookup purposes and overload with user-declared 176275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor// constructors and assignment operators. 186275e0cac39b76204644154fd99a449f57c589d4Douglas Gregornamespace PR6570 { 196275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor class A { }; 206275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor 216275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor class B { 226275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor public: 236275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor B() {} 246275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor 256275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor B(const A& a) { 266275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor operator = (CONST); 276275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor operator = (a); 286275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor } 296275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor 306275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor B& operator = (const A& a) { 316275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor return *this; 326275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor } 336275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor 346275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor void f(const A &a) { 356275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor B b(a); 366275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor }; 376275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor 386275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor static const B CONST; 396275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor }; 406275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor 416275e0cac39b76204644154fd99a449f57c589d4Douglas Gregor} 42cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl 43cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redlnamespace PR7594 { 44cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl // If the lazy declaration of special member functions is triggered 45cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl // in an out-of-line initializer, make sure the functions aren't in 46cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl // the initializer scope. This used to crash Clang: 47cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl struct C { 48cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl C(); 49cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl static C *c; 50cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl }; 51cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl C *C::c = new C(); 52cddc69fc3fe17b043a287a41e3706766c3d09a79Sebastian Redl} 53afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith 54afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smithnamespace Recursion { 55afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith template<typename T> struct InvokeCopyConstructor { 56afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith static const T &get(); 57afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith typedef decltype(T(get())) type; // expected-error {{no matching conver}} 58afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith }; 59afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith struct B; 60afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith struct A { 61651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // expected-note@-1 {{while substituting deduced template arguments}} 62afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith typedef B type; 63afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith template<typename T, 64afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith typename = typename InvokeCopyConstructor<typename T::type>::type> 65afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // expected-note@-1 {{in instantiation of template class}} 66afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith A(const T &); 67afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // expected-note@-1 {{in instantiation of default argument}} 68afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith }; 69afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith struct B { // expected-note {{candidate constructor (the implicit move }} 70afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith B(); // expected-note {{candidate constructor not viable}} 71afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith A a; 72afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith }; 73afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // Triggering the declaration of B's copy constructor causes overload 74afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // resolution to occur for A's copying constructor, which instantiates 75afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // InvokeCopyConstructor<B>, which triggers the declaration of B's copy 76afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // constructor. Notionally, this happens when we get to the end of the 77afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // definition of 'struct B', so there is no declared copy constructor yet. 78afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // 79afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // This behavior is g++-compatible, but isn't exactly right; the class is 80afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // supposed to be incomplete when we implicitly declare its special members. 81afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith B b = B(); 82afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith 83afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith 84afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // Another case, which isn't ill-formed under our rules. This is inspired by 85afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // a problem which occurs when combining CGAL with libstdc++-4.7. 86afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith 87afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith template<typename T> T &&declval(); 88afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith template<typename T, typename U> struct pair { 89afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith pair(); 90afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith template<typename V, typename W, 91afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith typename = decltype(T(declval<const V&>())), 92afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith typename = decltype(U(declval<const W&>()))> 93afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith pair(const pair<V,W> &); 94afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith }; 95afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith 96afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith template<typename K> struct Line; 97afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith 98afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith template<typename K> struct Vector { 99afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith Vector(const Line<K> &l); 100afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith }; 101afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith 102afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith template<typename K> struct Point { 103afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith Vector<K> v; 104afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith }; 105afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith 106afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith template<typename K> struct Line { 107afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith pair<Point<K>, Vector<K>> x; 108afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith }; 109afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith 110afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // Trigger declaration of Line copy ctor, which causes substitution into 111afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // pair's templated constructor, which triggers instantiation of the 112afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // definition of Point's copy constructor, which performs overload resolution 113afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // on Vector's constructors, which requires declaring all of Line's 114afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // constructors. That should not find a copy constructor (because we've not 115afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // declared it yet), but by the time we get all the way back here, we should 116afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith // find the copy constructor. 117afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith Line<void> L1; 118afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith Line<void> L2(L1); 119afb49189d6962f3636d6a93d09c0b495e94ac782Richard Smith} 120