[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / warn-missing-noreturn.cpp
blob400b471600e0277965cf7a8d0342d8a2ff04f06d
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -Wmissing-noreturn -Wreturn-type
2 void f() __attribute__((noreturn));
4 template<typename T> void g(T) {
5 f();
8 template void g<int>(int);
10 template<typename T> struct A {
11 void g() {
12 f();
16 template struct A<int>;
18 struct B {
19 template<typename T> void g(T) {
20 f();
24 template void B::g<int>(int);
26 // We don't want a warning here.
27 struct X {
28 virtual void g() { f(); }
31 namespace test1 {
32 bool condition();
34 // We don't want a warning here.
35 void foo() {
36 while (condition()) {}
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;
48 void f_R7880658(R7880658 f, R7880658 l) { // no-warning
49 for (; f != l; ++f) {
53 namespace test2 {
55 bool g();
56 void *h() __attribute__((noreturn));
57 void *j();
59 struct A {
60 void *f;
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()) { }
69 namespace test3 {
70 struct A {
71 ~A();
74 struct B {
75 ~B() { }
77 A a;
80 struct C : A {
81 ~C() { }
85 // Properly handle CFGs with destructors.
86 struct rdar8875247 {
87 ~rdar8875247 ();
89 void rdar8875247_aux();
91 int rdar8875247_test() {
92 rdar8875247 f;
93 } // expected-warning{{non-void function does not return a value}}
95 struct rdar8875247_B {
96 rdar8875247_B();
97 ~rdar8875247_B();
100 rdar8875247_B test_rdar8875247_B() {
101 rdar8875247_B f;
102 return f;
103 } // no-warning
105 namespace PR10801 {
106 struct Foo {
107 void wibble() __attribute((__noreturn__));
110 struct Bar {
111 void wibble();
114 template <typename T> void thingy(T thing) {
115 thing.wibble();
118 void test() {
119 Foo f;
120 Bar b;
121 thingy(f);
122 thingy(b);