Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 1 | // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.ExprInspection %s -verify |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 2 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 3 | constexpr int clang_analyzer_hashDump(int) { return 5; } |
| 4 | |
| 5 | void function(int) { |
| 6 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void function(int)$27$clang_analyzer_hashDump(5);$Category}} |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 7 | } |
| 8 | |
| 9 | namespace { |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 10 | void variadicParam(int, ...) { |
| 11 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void (anonymous namespace)::variadicParam(int, ...)$27$clang_analyzer_hashDump(5);$Category}} |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 12 | } |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 13 | } // namespace |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 14 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 15 | constexpr int f() { |
| 16 | return clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$int f()$34$returnclang_analyzer_hashDump(5);$Category}} |
| 17 | } |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 18 | |
| 19 | namespace AA { |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 20 | class X { |
| 21 | X() { |
| 22 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$AA::X::X()$29$clang_analyzer_hashDump(5);$Category}} |
| 23 | } |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 24 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 25 | static void static_method() { |
| 26 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::static_method()$29$clang_analyzer_hashDump(5);$Category}} |
| 27 | variadicParam(5); |
| 28 | } |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 29 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 30 | void method() && { |
| 31 | struct Y { |
| 32 | inline void method() const & { |
| 33 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::method()::Y::method() const &$33$clang_analyzer_hashDump(5);$Category}} |
| 34 | } |
| 35 | }; |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 36 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 37 | Y y; |
| 38 | y.method(); |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 39 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 40 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::method() &&$29$clang_analyzer_hashDump(5);$Category}} |
| 41 | } |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 42 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 43 | void OutOfLine(); |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 44 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 45 | X &operator=(int) { |
| 46 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$class AA::X & AA::X::operator=(int)$29$clang_analyzer_hashDump(5);$Category}} |
| 47 | return *this; |
| 48 | } |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 49 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 50 | operator int() { |
| 51 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$AA::X::operator int()$29$clang_analyzer_hashDump(5);$Category}} |
| 52 | return 0; |
| 53 | } |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 54 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 55 | explicit operator float() { |
| 56 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$AA::X::operator float()$29$clang_analyzer_hashDump(5);$Category}} |
| 57 | return 0; |
| 58 | } |
| 59 | }; |
| 60 | } // namespace AA |
| 61 | |
| 62 | void AA::X::OutOfLine() { |
| 63 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::OutOfLine()$27$clang_analyzer_hashDump(5);$Category}} |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void testLambda() { |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 67 | []() { |
| 68 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void testLambda()::(anonymous class)::operator()() const$29$clang_analyzer_hashDump(5);$Category}} |
Gabor Horvath | efec163 | 2015-10-22 11:53:04 +0000 | [diff] [blame] | 69 | }(); |
| 70 | } |
| 71 | |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 72 | template <typename T> |
| 73 | void f(T) { |
Gabor Horvath | 404fcd3 | 2017-10-30 12:16:07 +0000 | [diff] [blame] | 74 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void f(T)$27$clang_analyzer_hashDump(5);$Category}} |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | template <typename T> |
| 78 | struct TX { |
| 79 | void f(T) { |
Gabor Horvath | 404fcd3 | 2017-10-30 12:16:07 +0000 | [diff] [blame] | 80 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TX::f(T)$29$clang_analyzer_hashDump(5);$Category}} |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 81 | } |
| 82 | }; |
| 83 | |
| 84 | template <> |
| 85 | void f<long>(long) { |
| 86 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void f(long)$27$clang_analyzer_hashDump(5);$Category}} |
| 87 | } |
| 88 | |
| 89 | template <> |
| 90 | struct TX<long> { |
| 91 | void f(long) { |
| 92 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TX<long>::f(long)$29$clang_analyzer_hashDump(5);$Category}} |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | template <typename T> |
| 97 | struct TTX { |
| 98 | template<typename S> |
| 99 | void f(T, S) { |
Gabor Horvath | 404fcd3 | 2017-10-30 12:16:07 +0000 | [diff] [blame] | 100 | clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TTX::f(T, S)$29$clang_analyzer_hashDump(5);$Category}} |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 101 | } |
| 102 | }; |
| 103 | |
| 104 | void g() { |
Gabor Horvath | 404fcd3 | 2017-10-30 12:16:07 +0000 | [diff] [blame] | 105 | // TX<int> and TX<double> is instantiated from the same code with the same |
| 106 | // source locations. The same error happining in both of the instantiations |
| 107 | // should share the common hash. This means we should not include the |
| 108 | // template argument for these types in the function signature. |
| 109 | // Note that, we still want the hash to be different for explicit |
| 110 | // specializations. |
Gabor Horvath | 3bd24f9 | 2017-10-30 12:02:23 +0000 | [diff] [blame] | 111 | TX<int> x; |
| 112 | TX<double> y; |
| 113 | TX<long> xl; |
| 114 | x.f(1); |
| 115 | xl.f(1); |
| 116 | f(5); |
| 117 | f(3.0); |
| 118 | y.f(2); |
| 119 | TTX<int> z; |
| 120 | z.f<int>(5, 5); |
| 121 | f(5l); |
| 122 | } |