Anna Zaks | bfa9ab8 | 2013-01-24 23:15:30 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core,debug.ExprInspection -verify %s |
Jordan Rose | fdaa338 | 2012-07-03 22:55:57 +0000 | [diff] [blame] | 2 | void clang_analyzer_eval(bool); |
| 3 | |
Douglas Gregor | 90d26a4 | 2010-11-01 23:16:05 +0000 | [diff] [blame] | 4 | struct X0 { }; |
| 5 | bool operator==(const X0&, const X0&); |
| 6 | |
| 7 | // PR7287 |
| 8 | struct test { int a[2]; }; |
| 9 | |
| 10 | void t2() { |
| 11 | test p = {{1,2}}; |
| 12 | test q; |
| 13 | q = p; |
| 14 | } |
| 15 | |
| 16 | bool PR7287(X0 a, X0 b) { |
Douglas Gregor | 73a48ad | 2010-11-01 23:33:11 +0000 | [diff] [blame] | 17 | return operator==(a, b); |
Douglas Gregor | 90d26a4 | 2010-11-01 23:16:05 +0000 | [diff] [blame] | 18 | } |
Jordan Rose | fdaa338 | 2012-07-03 22:55:57 +0000 | [diff] [blame] | 19 | |
| 20 | |
| 21 | // Inlining non-static member operators mistakenly treated 'this' as the first |
| 22 | // argument for a while. |
| 23 | |
| 24 | struct IntComparable { |
| 25 | bool operator==(int x) const { |
| 26 | return x == 0; |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | void testMemberOperator(IntComparable B) { |
Jordan Rose | e54cfc7 | 2012-07-10 22:07:57 +0000 | [diff] [blame] | 31 | clang_analyzer_eval(B == 0); // expected-warning{{TRUE}} |
Jordan Rose | fdaa338 | 2012-07-03 22:55:57 +0000 | [diff] [blame] | 32 | } |
Jordan Rose | c386d8f | 2012-08-23 23:01:39 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | |
| 36 | namespace UserDefinedConversions { |
| 37 | class Convertible { |
| 38 | public: |
| 39 | operator int() const { |
| 40 | return 42; |
| 41 | } |
| 42 | operator bool() const { |
| 43 | return true; |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | void test(const Convertible &obj) { |
| 48 | clang_analyzer_eval((int)obj == 42); // expected-warning{{TRUE}} |
| 49 | clang_analyzer_eval(obj); // expected-warning{{TRUE}} |
| 50 | } |
| 51 | } |