1 // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.ExprInspection %s -verify
2
clang_analyzer_hashDump(int)3 constexpr int clang_analyzer_hashDump(int) { return 5; }
4
function(int)5 void function(int) {
6 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void function(int)$27$clang_analyzer_hashDump(5);$Category}}
7 }
8
9 namespace {
variadicParam(int,...)10 void variadicParam(int, ...) {
11 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void (anonymous namespace)::variadicParam(int, ...)$27$clang_analyzer_hashDump(5);$Category}}
12 }
13 } // namespace
14
f()15 constexpr int f() {
16 return clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$int f()$34$returnclang_analyzer_hashDump(5);$Category}}
17 }
18
19 namespace AA {
20 class X {
X()21 X() {
22 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$AA::X::X()$29$clang_analyzer_hashDump(5);$Category}}
23 }
24
static_method()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 }
29
method()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 };
36
37 Y y;
38 y.method();
39
40 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::method() &&$29$clang_analyzer_hashDump(5);$Category}}
41 }
42
43 void OutOfLine();
44
operator =(int)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 }
49
operator int()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 }
54
operator float()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
OutOfLine()62 void AA::X::OutOfLine() {
63 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::OutOfLine()$27$clang_analyzer_hashDump(5);$Category}}
64 }
65
testLambda()66 void testLambda() {
67 []() {
68 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void testLambda()::(anonymous class)::operator()() const$29$clang_analyzer_hashDump(5);$Category}}
69 }();
70 }
71
72 template <typename T>
f(T)73 void f(T) {
74 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void f(T)$27$clang_analyzer_hashDump(5);$Category}}
75 }
76
77 template <typename T>
78 struct TX {
fTX79 void f(T) {
80 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TX::f(T)$29$clang_analyzer_hashDump(5);$Category}}
81 }
82 };
83
84 template <>
f(long)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> {
fTX91 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>
fTTX99 void f(T, S) {
100 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TTX::f(T, S)$29$clang_analyzer_hashDump(5);$Category}}
101 }
102 };
103
g()104 void g() {
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.
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 }
123