1 // RUN: %clang_cc1 -std=c++11 -verify %s
2 
3 // rdar://12240916 stack overflow.
4 namespace rdar12240916 {
5 
6 struct S2 {
7   S2(const S2&);
8   S2();
9 };
10 
11 struct S { // expected-note {{not complete}}
12   S x; // expected-error {{incomplete type}}
13   S2 y;
14 };
15 
foo()16 S foo() {
17   S s;
18   return s;
19 }
20 
21 struct S3; // expected-note {{forward declaration}}
22 
23 struct S4 {
24   S3 x; // expected-error {{incomplete type}}
25   S2 y;
26 };
27 
28 struct S3 {
29   S4 x;
30   S2 y;
31 };
32 
foo2()33 S4 foo2() {
34   S4 s;
35   return s;
36 }
37 
38 }
39 
40 // rdar://12542261 stack overflow.
41 namespace rdar12542261 {
42 
43 template <class _Tp>
44 struct check_complete
45 {
46   static_assert(sizeof(_Tp) > 0, "Type must be complete.");
47 };
48 
49 
50 template<class _Rp>
51 class function // expected-note 2 {{candidate}}
52 {
53 public:
54   template<class _Fp>
55   function(_Fp, typename check_complete<_Fp>::type* = 0);  // expected-note {{candidate}}
56 };
57 
foobar()58 void foobar()
59 {
60   auto LeftCanvas = new Canvas(); // expected-error {{unknown type name}}
61   function<void()> m_OnChange = [&, LeftCanvas]() { }; // expected-error {{no viable conversion}}
62 }
63 
64 }
65 
66 namespace b6981007 {
67   struct S {}; // expected-note 3{{candidate}}
f()68   void f() {
69     S s(1, 2, 3); // expected-error {{no matching}}
70     for (auto x : s) { // expected-error {{invalid range expression of}}
71       // We used to attempt to evaluate the initializer of this variable,
72       // and crash because it has an undeduced type.
73       const int &n(x);
74       constexpr int k = sizeof(x);
75     }
76   }
77 }
78 
79 namespace incorrect_auto_type_deduction_for_typo {
80 struct S {
Sincorrect_auto_type_deduction_for_typo::S81   template <typename T> S(T t) {
82     (void)sizeof(t);
83     (void)new auto(t);
84   }
85 };
86 
87 void Foo(S);
88 
test(int some_number)89 void test(int some_number) {  // expected-note {{'some_number' declared here}}
90   auto x = sum_number;  // expected-error {{use of undeclared identifier 'sum_number'; did you mean 'some_number'?}}
91   auto lambda = [x] {};
92   Foo(lambda);
93 }
94 }
95 
96 namespace pr29091 {
97   struct X{ X(const X &x); };
98   struct Y: X { using X::X; };
foo()99   bool foo() { return __has_nothrow_constructor(Y); }
bar()100   bool bar() { return __has_nothrow_copy(Y); }
101 
102   struct A { template <typename T> A(); };
103   struct B : A { using A::A; };
baz()104   bool baz() { return __has_nothrow_constructor(B); }
qux()105   bool qux() { return __has_nothrow_copy(B); }
106 }
107