| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wmissing-noreturn -Wreturn-type |
| 2 |
void f() __attribute__((noreturn)); |
| 3 |
|
| 4 |
template<typename T> void g(T) { |
| 5 |
f(); |
| 6 |
} |
| 7 |
|
| 8 |
template void g<int>(int); |
| 9 |
|
| 10 |
template<typename T> struct A { |
| 11 |
void g() { |
| 12 |
f(); |
| 13 |
} |
| 14 |
}; |
| 15 |
|
| 16 |
template struct A<int>; |
| 17 |
|
| 18 |
struct B { |
| 19 |
template<typename T> void g(T) { |
| 20 |
f(); |
| 21 |
} |
| 22 |
}; |
| 23 |
|
| 24 |
template void B::g<int>(int); |
| 25 |
|
| 26 |
// We don't want a warning here. |
| 27 |
struct X { |
| 28 |
virtual void g() { f(); } |
| 29 |
}; |
| 30 |
|
| 31 |
namespace test1 { |
| 32 |
bool condition(); |
| 33 |
|
| 34 |
// We don't want a warning here. |
| 35 |
void foo() { |
| 36 |
while (condition()) {} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
// This test case previously had a false "missing return" warning. |
| 42 |
struct R7880658 { |
| 43 |
R7880658 &operator++(); |
| 44 |
bool operator==(const R7880658 &) const; |
| 45 |
bool operator!=(const R7880658 &) const; |
| 46 |
}; |
| 47 |
|
| 48 |
void f_R7880658(R7880658 f, R7880658 l) { // no-warning |
| 49 |
for (; f != l; ++f) { |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
namespace test2 { |
| 54 |
|
| 55 |
bool g(); |
| 56 |
void *h() __attribute__((noreturn)); |
| 57 |
void *j(); |
| 58 |
|
| 59 |
struct A { |
| 60 |
void *f; |
| 61 |
|
| 62 |
A() : f(0) { } |
| 63 |
A(int) : f(h()) { } // expected-warning {{function 'A' could be declared with attribute 'noreturn'}} |
| 64 |
A(char) : f(j()) { } |
| 65 |
A(bool b) : f(b ? h() : j()) { } |
| 66 |
}; |
| 67 |
} |
| 68 |
|
| 69 |
namespace test3 { |
| 70 |
struct A { |
| 71 |
~A(); |
| 72 |
}; |
| 73 |
|
| 74 |
struct B { |
| 75 |
~B() { } |
| 76 |
|
| 77 |
A a; |
| 78 |
}; |
| 79 |
|
| 80 |
struct C : A { |
| 81 |
~C() { } |
| 82 |
}; |
| 83 |
} |
| 84 |
|
| 85 |
// Properly handle CFGs with destructors. |
| 86 |
struct rdar8875247 { |
| 87 |
~rdar8875247 (); |
| 88 |
}; |
| 89 |
void rdar8875247_aux(); |
| 90 |
|
| 91 |
struct rdar8875247_B { |
| 92 |
rdar8875247_B(); |
| 93 |
~rdar8875247_B(); |
| 94 |
}; |
| 95 |
|
| 96 |
rdar8875247_B test_rdar8875247_B() { |
| 97 |
rdar8875247_B f; |
| 98 |
return f; |
| 99 |
} // no-warning |
| 100 |
|
| 101 |
namespace PR10801 { |
| 102 |
struct Foo { |
| 103 |
void wibble() __attribute((__noreturn__)); |
| 104 |
}; |
| 105 |
|
| 106 |
struct Bar { |
| 107 |
void wibble(); |
| 108 |
}; |
| 109 |
|
| 110 |
template <typename T> void thingy(T thing) { |
| 111 |
thing.wibble(); |
| 112 |
} |
| 113 |
|
| 114 |
void test() { |
| 115 |
Foo f; |
| 116 |
Bar b; |
| 117 |
thingy(f); |
| 118 |
thingy(b); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
namespace GH63009 { |
| 123 |
struct S2 { |
| 124 |
[[noreturn]] ~S2(); |
| 125 |
}; |
| 126 |
|
| 127 |
int foo(); |
| 128 |
|
| 129 |
int test_2() { |
| 130 |
S2 s2; |
| 131 |
foo(); |
| 132 |
} |
| 133 |
} |