blob: 8072ac6b8249a5b2f6bc7cfcc90c7b25303828d9 [file] [log] [blame]
Ted Kremenek8b3b3db2011-01-25 22:57:41 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s -Wmissing-noreturn -Wreturn-type
Anders Carlsson4855a522010-02-06 05:31:15 +00002void f() __attribute__((noreturn));
3
Douglas Gregorfcdd2cb2011-10-10 18:15:57 +00004template<typename T> void g(T) {
Anders Carlsson4855a522010-02-06 05:31:15 +00005 f();
6}
7
Douglas Gregorfcdd2cb2011-10-10 18:15:57 +00008template void g<int>(int);
Anders Carlsson4855a522010-02-06 05:31:15 +00009
10template<typename T> struct A {
Douglas Gregorfcdd2cb2011-10-10 18:15:57 +000011 void g() {
Anders Carlsson4855a522010-02-06 05:31:15 +000012 f();
13 }
14};
15
Douglas Gregorfcdd2cb2011-10-10 18:15:57 +000016template struct A<int>;
Anders Carlsson4855a522010-02-06 05:31:15 +000017
18struct B {
Douglas Gregorfcdd2cb2011-10-10 18:15:57 +000019 template<typename T> void g(T) {
Anders Carlsson4855a522010-02-06 05:31:15 +000020 f();
21 }
22};
23
Douglas Gregorfcdd2cb2011-10-10 18:15:57 +000024template void B::g<int>(int);
Douglas Gregorca7eaee2010-04-16 23:28:44 +000025
26// We don't want a warning here.
27struct X {
28 virtual void g() { f(); }
29};
John McCall259d48e2010-04-30 07:10:06 +000030
31namespace test1 {
32 bool condition();
33
34 // We don't want a warning here.
35 void foo() {
36 while (condition()) {}
37 }
38}
Ted Kremenek01b0cfa2010-05-13 06:58:45 +000039
40
41// <rdar://problem/7880658> - This test case previously had a false "missing return"
42// warning.
43struct R7880658 {
44 R7880658 &operator++();
45 bool operator==(const R7880658 &) const;
46 bool operator!=(const R7880658 &) const;
47};
48
49void f_R7880658(R7880658 f, R7880658 l) { // no-warning
50 for (; f != l; ++f) {
51 }
52}
Anders Carlsson0dc5f9a2011-01-16 22:12:43 +000053
54namespace test2 {
55
56 bool g();
57 void *h() __attribute__((noreturn));
58 void *j();
59
60 struct A {
61 void *f;
62
63 A() : f(0) { }
Chandler Carruthb0656ec2011-08-31 09:01:53 +000064 A(int) : f(h()) { } // expected-warning {{function 'A' could be declared with attribute 'noreturn'}}
Anders Carlsson0dc5f9a2011-01-16 22:12:43 +000065 A(char) : f(j()) { }
66 A(bool b) : f(b ? h() : j()) { }
67 };
Anders Carlsson22c41202011-01-17 19:06:31 +000068}
Anders Carlsson0dc5f9a2011-01-16 22:12:43 +000069
Anders Carlsson22c41202011-01-17 19:06:31 +000070namespace test3 {
71 struct A {
72 ~A();
73 };
74
75 struct B {
76 ~B() { }
77
78 A a;
79 };
80
81 struct C : A {
82 ~C() { }
83 };
Anders Carlsson0dc5f9a2011-01-16 22:12:43 +000084}
Ted Kremenek8b3b3db2011-01-25 22:57:41 +000085
86// <rdar://problem/8875247> - Properly handle CFGs with destructors.
87struct rdar8875247 {
88 ~rdar8875247 ();
89};
90void rdar8875247_aux();
91
92int rdar8875247_test() {
93 rdar8875247 f;
94} // expected-warning{{control reaches end of non-void function}}
95
Ted Kremenek5811f592011-01-26 04:49:52 +000096struct rdar8875247_B {
97 rdar8875247_B();
98 ~rdar8875247_B();
99};
100
101rdar8875247_B test_rdar8875247_B() {
102 rdar8875247_B f;
103 return f;
104} // no-warning
105
Douglas Gregorfcdd2cb2011-10-10 18:15:57 +0000106namespace PR10801 {
107 struct Foo {
108 void wibble() __attribute((__noreturn__));
109 };
110
111 struct Bar {
112 void wibble();
113 };
114
115 template <typename T> void thingy(T thing) {
116 thing.wibble();
117 }
118
119 void test() {
120 Foo f;
121 Bar b;
122 thingy(f);
123 thingy(b);
124 }
125}