File: warn-missing-noreturn.cpp

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,388 kB
  • sloc: cpp: 7,438,767; ansic: 1,393,871; asm: 1,012,926; python: 241,728; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (133 lines) | stat: -rw-r--r-- 1,931 bytes parent folder | download | duplicates (11)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wmissing-noreturn -Wreturn-type
void f() __attribute__((noreturn));

template<typename T> void g(T) {
  f();
}

template void g<int>(int);

template<typename T> struct A {
  void g() {
    f();
  }
};

template struct A<int>;

struct B {
  template<typename T> void g(T) {
    f();
  }
};

template void B::g<int>(int);

// We don't want a warning here.
struct X {
  virtual void g() { f(); }
};

namespace test1 {
  bool condition();

  // We don't want a warning here.
  void foo() {
    while (condition()) {}
  }
}


// This test case previously had a false "missing return" warning.
struct R7880658 {
  R7880658 &operator++();
  bool operator==(const R7880658 &) const;
  bool operator!=(const R7880658 &) const;
};

void f_R7880658(R7880658 f, R7880658 l) {  // no-warning
  for (; f != l; ++f) {
  }
}

namespace test2 {

  bool g();
  void *h() __attribute__((noreturn));
  void *j();

  struct A {
    void *f;

    A() : f(0) { }
    A(int) : f(h()) { } // expected-warning {{function 'A' could be declared with attribute 'noreturn'}}
    A(char) : f(j()) { }
    A(bool b) : f(b ? h() : j()) { }
  };
}

namespace test3 {
  struct A {
    ~A();
  };

  struct B {
    ~B() { }

    A a;
  };

  struct C : A { 
    ~C() { }
  };
}

// Properly handle CFGs with destructors.
struct rdar8875247 {
  ~rdar8875247 ();
};
void rdar8875247_aux();

struct rdar8875247_B {
  rdar8875247_B();
  ~rdar8875247_B();
};

rdar8875247_B test_rdar8875247_B() {
  rdar8875247_B f;
  return f;
} // no-warning

namespace PR10801 {
  struct Foo {
    void wibble() __attribute((__noreturn__));
  };

  struct Bar {
    void wibble();
  };

  template <typename T> void thingy(T thing) {
    thing.wibble();
  }

  void test() {
    Foo f;
    Bar b;
    thingy(f);
    thingy(b);
  }
}

namespace GH63009 {
struct S2 {
  [[noreturn]] ~S2();
};

int foo();

int test_2() {
  S2 s2;
  foo();
}
}