Debian Codegraph @

clang/test/SemaCXX/wreturn-always-throws.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wreturn-type -Winvalid-noreturn -verify %s
2 // expected-no-diagnostics
3
4 namespace std {
5 class string {
6 public:
7 string(const char*); // constructor for runtime_error
8 };
9 class runtime_error {
10 public:
11 runtime_error(const string &);
12 };
13 }
14
15 // Non-template version.
16
17 void throwError(const std::string& msg) {
18 throw std::runtime_error(msg);
19 }
20
21 int ensureZero(const int i) {
22 if (i == 0) return 0;
23 throwError("ERROR"); // no-warning
24 }
25
26 int alwaysThrows() {
27 throw std::runtime_error("This function always throws"); // no-warning
28 }
29
30 // Template version.
31
32 template<typename T>
33 void throwErrorTemplate(const T& msg) {
34 throw msg;
35 }
36
37 template <typename T>
38 int ensureZeroTemplate(T i) {
39 if (i == 0) return 0;
40 throwErrorTemplate("ERROR"); // no-warning
41 }
42
43 void testTemplates() {
44 throwErrorTemplate("ERROR");
45 (void)ensureZeroTemplate(42);
46 }
47
48 // Ensure that explicit specialization of a member function does not inherit
49 // the warning from the primary template.
50
51 template<typename T>
52 struct S {
53 void f();
54 void g();
55 };
56
57 template<typename T>
58 void S<T>::f() { throw 0; }
59 template<>
60 void S<int>::f() {}
61
62 template<typename T>
63 void S<T>::g() {}
64 template<>
65 void S<int>::g() { throw 0; }