blob: f397d181e665697023e7bdba8e1c21544166eb3f [file] [log] [blame]
Gabor Horvath3bd24f92017-10-30 12:02:23 +00001// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.ExprInspection %s -verify
Gabor Horvathefec1632015-10-22 11:53:04 +00002
Gabor Horvath3bd24f92017-10-30 12:02:23 +00003constexpr int clang_analyzer_hashDump(int) { return 5; }
4
5void function(int) {
6 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void function(int)$27$clang_analyzer_hashDump(5);$Category}}
Gabor Horvathefec1632015-10-22 11:53:04 +00007}
8
9namespace {
Gabor Horvath3bd24f92017-10-30 12:02:23 +000010void variadicParam(int, ...) {
11 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void (anonymous namespace)::variadicParam(int, ...)$27$clang_analyzer_hashDump(5);$Category}}
Gabor Horvathefec1632015-10-22 11:53:04 +000012}
Gabor Horvath3bd24f92017-10-30 12:02:23 +000013} // namespace
Gabor Horvathefec1632015-10-22 11:53:04 +000014
Gabor Horvath3bd24f92017-10-30 12:02:23 +000015constexpr int f() {
16 return clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$int f()$34$returnclang_analyzer_hashDump(5);$Category}}
17}
Gabor Horvathefec1632015-10-22 11:53:04 +000018
19namespace AA {
Gabor Horvath3bd24f92017-10-30 12:02:23 +000020class X {
21 X() {
22 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$AA::X::X()$29$clang_analyzer_hashDump(5);$Category}}
23 }
Gabor Horvathefec1632015-10-22 11:53:04 +000024
Gabor Horvath3bd24f92017-10-30 12:02:23 +000025 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 Horvathefec1632015-10-22 11:53:04 +000029
Gabor Horvath3bd24f92017-10-30 12:02:23 +000030 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 Horvathefec1632015-10-22 11:53:04 +000036
Gabor Horvath3bd24f92017-10-30 12:02:23 +000037 Y y;
38 y.method();
Gabor Horvathefec1632015-10-22 11:53:04 +000039
Gabor Horvath3bd24f92017-10-30 12:02:23 +000040 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::method() &&$29$clang_analyzer_hashDump(5);$Category}}
41 }
Gabor Horvathefec1632015-10-22 11:53:04 +000042
Gabor Horvath3bd24f92017-10-30 12:02:23 +000043 void OutOfLine();
Gabor Horvathefec1632015-10-22 11:53:04 +000044
Gabor Horvath3bd24f92017-10-30 12:02:23 +000045 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 Horvathefec1632015-10-22 11:53:04 +000049
Gabor Horvath3bd24f92017-10-30 12:02:23 +000050 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 Horvathefec1632015-10-22 11:53:04 +000054
Gabor Horvath3bd24f92017-10-30 12:02:23 +000055 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
62void AA::X::OutOfLine() {
63 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void AA::X::OutOfLine()$27$clang_analyzer_hashDump(5);$Category}}
Gabor Horvathefec1632015-10-22 11:53:04 +000064}
65
66void testLambda() {
Gabor Horvath3bd24f92017-10-30 12:02:23 +000067 []() {
68 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void testLambda()::(anonymous class)::operator()() const$29$clang_analyzer_hashDump(5);$Category}}
Gabor Horvathefec1632015-10-22 11:53:04 +000069 }();
70}
71
Gabor Horvath3bd24f92017-10-30 12:02:23 +000072template <typename T>
73void f(T) {
Gabor Horvath404fcd32017-10-30 12:16:07 +000074 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void f(T)$27$clang_analyzer_hashDump(5);$Category}}
Gabor Horvath3bd24f92017-10-30 12:02:23 +000075}
76
77template <typename T>
78struct TX {
79 void f(T) {
Gabor Horvath404fcd32017-10-30 12:16:07 +000080 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TX::f(T)$29$clang_analyzer_hashDump(5);$Category}}
Gabor Horvath3bd24f92017-10-30 12:02:23 +000081 }
82};
83
84template <>
85void f<long>(long) {
86 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void f(long)$27$clang_analyzer_hashDump(5);$Category}}
87}
88
89template <>
90struct 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
96template <typename T>
97struct TTX {
98 template<typename S>
99 void f(T, S) {
Gabor Horvath404fcd32017-10-30 12:16:07 +0000100 clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TTX::f(T, S)$29$clang_analyzer_hashDump(5);$Category}}
Gabor Horvath3bd24f92017-10-30 12:02:23 +0000101 }
102};
103
104void g() {
Gabor Horvath404fcd32017-10-30 12:16:07 +0000105 // 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 Horvath3bd24f92017-10-30 12:02:23 +0000111 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}