1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2*67e74705SXin Li
3*67e74705SXin Li struct A { };
A()4*67e74705SXin Li A::A() { } // expected-error {{definition of implicitly declared default constructor}}
5*67e74705SXin Li
6*67e74705SXin Li struct B { };
B(const B &)7*67e74705SXin Li B::B(const B&) { } // expected-error {{definition of implicitly declared copy constructor}}
8*67e74705SXin Li
9*67e74705SXin Li struct C { };
operator =(const C &)10*67e74705SXin Li C& C::operator=(const C&) { return *this; } // expected-error {{definition of implicitly declared copy assignment operator}}
11*67e74705SXin Li
12*67e74705SXin Li struct D { };
~D()13*67e74705SXin Li D::~D() { } // expected-error {{definition of implicitly declared destructor}}
14*67e74705SXin Li
15*67e74705SXin Li // Make sure that the special member functions are introduced for
16*67e74705SXin Li // name-lookup purposes and overload with user-declared
17*67e74705SXin Li // constructors and assignment operators.
18*67e74705SXin Li namespace PR6570 {
19*67e74705SXin Li class A { };
20*67e74705SXin Li
21*67e74705SXin Li class B {
22*67e74705SXin Li public:
B()23*67e74705SXin Li B() {}
24*67e74705SXin Li
B(const A & a)25*67e74705SXin Li B(const A& a) {
26*67e74705SXin Li operator = (CONST);
27*67e74705SXin Li operator = (a);
28*67e74705SXin Li }
29*67e74705SXin Li
operator =(const A & a)30*67e74705SXin Li B& operator = (const A& a) {
31*67e74705SXin Li return *this;
32*67e74705SXin Li }
33*67e74705SXin Li
f(const A & a)34*67e74705SXin Li void f(const A &a) {
35*67e74705SXin Li B b(a);
36*67e74705SXin Li };
37*67e74705SXin Li
38*67e74705SXin Li static const B CONST;
39*67e74705SXin Li };
40*67e74705SXin Li
41*67e74705SXin Li }
42*67e74705SXin Li
43*67e74705SXin Li namespace PR7594 {
44*67e74705SXin Li // If the lazy declaration of special member functions is triggered
45*67e74705SXin Li // in an out-of-line initializer, make sure the functions aren't in
46*67e74705SXin Li // the initializer scope. This used to crash Clang:
47*67e74705SXin Li struct C {
48*67e74705SXin Li C();
49*67e74705SXin Li static C *c;
50*67e74705SXin Li };
51*67e74705SXin Li C *C::c = new C();
52*67e74705SXin Li }
53*67e74705SXin Li
54*67e74705SXin Li namespace Recursion {
55*67e74705SXin Li template<typename T> struct InvokeCopyConstructor {
56*67e74705SXin Li static const T &get();
57*67e74705SXin Li typedef decltype(T(get())) type; // expected-error {{no matching conver}}
58*67e74705SXin Li };
59*67e74705SXin Li struct B;
60*67e74705SXin Li struct A {
61*67e74705SXin Li // expected-note@-1 {{while substituting deduced template arguments}}
62*67e74705SXin Li typedef B type;
63*67e74705SXin Li template<typename T,
64*67e74705SXin Li typename = typename InvokeCopyConstructor<typename T::type>::type>
65*67e74705SXin Li // expected-note@-1 {{in instantiation of template class}}
66*67e74705SXin Li A(const T &);
67*67e74705SXin Li // expected-note@-1 {{in instantiation of default argument}}
68*67e74705SXin Li };
69*67e74705SXin Li struct B { // expected-note {{candidate constructor (the implicit move }}
70*67e74705SXin Li B(); // expected-note {{candidate constructor not viable}}
71*67e74705SXin Li A a;
72*67e74705SXin Li };
73*67e74705SXin Li // Triggering the declaration of B's copy constructor causes overload
74*67e74705SXin Li // resolution to occur for A's copying constructor, which instantiates
75*67e74705SXin Li // InvokeCopyConstructor<B>, which triggers the declaration of B's copy
76*67e74705SXin Li // constructor. Notionally, this happens when we get to the end of the
77*67e74705SXin Li // definition of 'struct B', so there is no declared copy constructor yet.
78*67e74705SXin Li //
79*67e74705SXin Li // This behavior is g++-compatible, but isn't exactly right; the class is
80*67e74705SXin Li // supposed to be incomplete when we implicitly declare its special members.
81*67e74705SXin Li B b = B();
82*67e74705SXin Li
83*67e74705SXin Li
84*67e74705SXin Li // Another case, which isn't ill-formed under our rules. This is inspired by
85*67e74705SXin Li // a problem which occurs when combining CGAL with libstdc++-4.7.
86*67e74705SXin Li
87*67e74705SXin Li template<typename T> T &&declval();
88*67e74705SXin Li template<typename T, typename U> struct pair {
89*67e74705SXin Li pair();
90*67e74705SXin Li template<typename V, typename W,
91*67e74705SXin Li typename = decltype(T(declval<const V&>())),
92*67e74705SXin Li typename = decltype(U(declval<const W&>()))>
93*67e74705SXin Li pair(const pair<V,W> &);
94*67e74705SXin Li };
95*67e74705SXin Li
96*67e74705SXin Li template<typename K> struct Line;
97*67e74705SXin Li
98*67e74705SXin Li template<typename K> struct Vector {
99*67e74705SXin Li Vector(const Line<K> &l);
100*67e74705SXin Li };
101*67e74705SXin Li
102*67e74705SXin Li template<typename K> struct Point {
103*67e74705SXin Li Vector<K> v;
104*67e74705SXin Li };
105*67e74705SXin Li
106*67e74705SXin Li template<typename K> struct Line {
107*67e74705SXin Li pair<Point<K>, Vector<K>> x;
108*67e74705SXin Li };
109*67e74705SXin Li
110*67e74705SXin Li // Trigger declaration of Line copy ctor, which causes substitution into
111*67e74705SXin Li // pair's templated constructor, which triggers instantiation of the
112*67e74705SXin Li // definition of Point's copy constructor, which performs overload resolution
113*67e74705SXin Li // on Vector's constructors, which requires declaring all of Line's
114*67e74705SXin Li // constructors. That should not find a copy constructor (because we've not
115*67e74705SXin Li // declared it yet), but by the time we get all the way back here, we should
116*67e74705SXin Li // find the copy constructor.
117*67e74705SXin Li Line<void> L1;
118*67e74705SXin Li Line<void> L2(L1);
119*67e74705SXin Li }
120