xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/cxx11-crashes.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // rdar://12240916 stack overflow.
4*f4a2713aSLionel Sambuc namespace rdar12240916 {
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc struct S2 {
7*f4a2713aSLionel Sambuc   S2(const S2&);
8*f4a2713aSLionel Sambuc   S2();
9*f4a2713aSLionel Sambuc };
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc struct S { // expected-note {{not complete}}
12*f4a2713aSLionel Sambuc   S x; // expected-error {{incomplete type}}
13*f4a2713aSLionel Sambuc   S2 y;
14*f4a2713aSLionel Sambuc };
15*f4a2713aSLionel Sambuc 
foo()16*f4a2713aSLionel Sambuc S foo() {
17*f4a2713aSLionel Sambuc   S s;
18*f4a2713aSLionel Sambuc   return s;
19*f4a2713aSLionel Sambuc }
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc struct S3; // expected-note {{forward declaration}}
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc struct S4 {
24*f4a2713aSLionel Sambuc   S3 x; // expected-error {{incomplete type}}
25*f4a2713aSLionel Sambuc   S2 y;
26*f4a2713aSLionel Sambuc };
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc struct S3 {
29*f4a2713aSLionel Sambuc   S4 x;
30*f4a2713aSLionel Sambuc   S2 y;
31*f4a2713aSLionel Sambuc };
32*f4a2713aSLionel Sambuc 
foo2()33*f4a2713aSLionel Sambuc S4 foo2() {
34*f4a2713aSLionel Sambuc   S4 s;
35*f4a2713aSLionel Sambuc   return s;
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc }
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc // rdar://12542261 stack overflow.
41*f4a2713aSLionel Sambuc namespace rdar12542261 {
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc template <class _Tp>
44*f4a2713aSLionel Sambuc struct check_complete
45*f4a2713aSLionel Sambuc {
46*f4a2713aSLionel Sambuc   static_assert(sizeof(_Tp) > 0, "Type must be complete.");
47*f4a2713aSLionel Sambuc };
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc template<class _Rp>
51*f4a2713aSLionel Sambuc class function // expected-note 2 {{candidate}}
52*f4a2713aSLionel Sambuc {
53*f4a2713aSLionel Sambuc public:
54*f4a2713aSLionel Sambuc   template<class _Fp>
55*f4a2713aSLionel Sambuc   function(_Fp, typename check_complete<_Fp>::type* = 0);  // expected-note {{candidate}}
56*f4a2713aSLionel Sambuc };
57*f4a2713aSLionel Sambuc 
foobar()58*f4a2713aSLionel Sambuc void foobar()
59*f4a2713aSLionel Sambuc {
60*f4a2713aSLionel Sambuc   auto LeftCanvas = new Canvas(); // expected-error {{unknown type name}}
61*f4a2713aSLionel Sambuc   function<void()> m_OnChange = [&, LeftCanvas]() { }; // expected-error {{no viable conversion}}
62*f4a2713aSLionel Sambuc }
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc }
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc namespace b6981007 {
67*f4a2713aSLionel Sambuc   struct S {}; // expected-note 3{{candidate}}
f()68*f4a2713aSLionel Sambuc   void f() {
69*f4a2713aSLionel Sambuc     S s(1, 2, 3); // expected-error {{no matching}}
70*f4a2713aSLionel Sambuc     for (auto x : s) {
71*f4a2713aSLionel Sambuc       // We used to attempt to evaluate the initializer of this variable,
72*f4a2713aSLionel Sambuc       // and crash because it has an undeduced type.
73*f4a2713aSLionel Sambuc       const int &n(x);
74*f4a2713aSLionel Sambuc     }
75*f4a2713aSLionel Sambuc   }
76*f4a2713aSLionel Sambuc }
77