xref: /minix3/external/bsd/llvm/dist/clang/test/Analysis/member-expr.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection %s -verify
2f4a2713aSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc void clang_analyzer_checkInlined(bool);
4f4a2713aSLionel Sambuc void clang_analyzer_eval(int);
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc namespace EnumsViaMemberExpr {
7f4a2713aSLionel Sambuc   struct Foo {
8f4a2713aSLionel Sambuc     enum E {
9f4a2713aSLionel Sambuc       Bar = 1
10f4a2713aSLionel Sambuc     };
11f4a2713aSLionel Sambuc   };
12f4a2713aSLionel Sambuc 
testEnumVal(Foo Baz)13f4a2713aSLionel Sambuc   void testEnumVal(Foo Baz) {
14f4a2713aSLionel Sambuc     clang_analyzer_eval(Baz.Bar == Foo::Bar); // expected-warning{{TRUE}}
15f4a2713aSLionel Sambuc   }
16f4a2713aSLionel Sambuc 
testEnumRef(Foo & Baz)17f4a2713aSLionel Sambuc   void testEnumRef(Foo &Baz) {
18f4a2713aSLionel Sambuc     clang_analyzer_eval(Baz.Bar == Foo::Bar); // expected-warning{{TRUE}}
19f4a2713aSLionel Sambuc   }
20f4a2713aSLionel Sambuc 
testEnumPtr(Foo * Baz)21f4a2713aSLionel Sambuc   void testEnumPtr(Foo *Baz) {
22f4a2713aSLionel Sambuc     clang_analyzer_eval(Baz->Bar == Foo::Bar); // expected-warning{{TRUE}}
23f4a2713aSLionel Sambuc   }
24f4a2713aSLionel Sambuc }
25*0a6a1f1dSLionel Sambuc 
26*0a6a1f1dSLionel Sambuc namespace PR19531 {
27*0a6a1f1dSLionel Sambuc   struct A {
APR19531::A28*0a6a1f1dSLionel Sambuc     A() : x(0) {}
29*0a6a1f1dSLionel Sambuc     bool h() const;
30*0a6a1f1dSLionel Sambuc     int x;
31*0a6a1f1dSLionel Sambuc   };
32*0a6a1f1dSLionel Sambuc 
33*0a6a1f1dSLionel Sambuc   struct B {
gPR19531::B34*0a6a1f1dSLionel Sambuc     void g(bool (A::*mp_f)() const) {
35*0a6a1f1dSLionel Sambuc       // This used to trigger an assertion because the 'this' pointer is a
36*0a6a1f1dSLionel Sambuc       // temporary.
37*0a6a1f1dSLionel Sambuc       (A().*mp_f)();
38*0a6a1f1dSLionel Sambuc     }
fPR19531::B39*0a6a1f1dSLionel Sambuc     void f() { g(&A::h); }
40*0a6a1f1dSLionel Sambuc   };
41*0a6a1f1dSLionel Sambuc }
42