summaryrefslogtreecommitdiff
path: root/test/SemaCXX/cxx11-crashes.cpp
blob: 7c455eecd5fa3ff279a8401ca5c6ee0e4519247b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// RUN: %clang_cc1 -std=c++11 -verify %s

// rdar://12240916 stack overflow.
namespace rdar12240916 {

struct S2 {
  S2(const S2&);
  S2();
};

struct S { // expected-note {{not complete}}
  S x; // expected-error {{incomplete type}}
  S2 y;
};

S foo() {
  S s;
  return s;
}

struct S3; // expected-note {{forward declaration}}

struct S4 {
  S3 x; // expected-error {{incomplete type}}
  S2 y;
};

struct S3 {
  S4 x;
  S2 y;
};

S4 foo2() {
  S4 s;
  return s;
}

}

// rdar://12542261 stack overflow.
namespace rdar12542261 {

template <class _Tp>
struct check_complete
{
  static_assert(sizeof(_Tp) > 0, "Type must be complete.");
};


template<class _Rp>
class function // expected-note 2 {{candidate}}
{
public:
  template<class _Fp>
  function(_Fp, typename check_complete<_Fp>::type* = 0);  // expected-note {{candidate}}
};

void foobar()
{
  auto LeftCanvas = new Canvas(); // expected-error {{unknown type name}}
  function<void()> m_OnChange = [&, LeftCanvas]() { }; // expected-error {{no viable conversion}}
}

}

namespace b6981007 {
  struct S {}; // expected-note 3{{candidate}}
  void f() {
    S s(1, 2, 3); // expected-error {{no matching}}
    for (auto x : s) {
      // We used to attempt to evaluate the initializer of this variable,
      // and crash because it has an undeduced type.
      const int &n(x);
    }
  }
}

namespace incorrect_auto_type_deduction_for_typo {
struct S {
  template <typename T> S(T t) {
    (void)sizeof(t);
    (void)new auto(t);
  }
};

void Foo(S);

void test(int some_number) {  // expected-note {{'some_number' declared here}}
  auto x = sum_number;  // expected-error {{use of undeclared identifier 'sum_number'; did you mean 'some_number'?}}
  auto lambda = [x] {};
  Foo(lambda);
}
}

namespace pr29091 {
  struct X{ X(const X &x); };
  struct Y: X { using X::X; };
  bool foo() { return __has_nothrow_constructor(Y); }
  bool bar() { return __has_nothrow_copy(Y); }

  struct A { template <typename T> A(); };
  struct B : A { using A::A; };
  bool baz() { return __has_nothrow_constructor(B); }
  bool qux() { return __has_nothrow_copy(B); }
}