1 // RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core,debug.ExprInspection -verify %s
3 void clang_analyzer_eval(bool);
10 bool PR14634_implicit(int x
) {
15 void intAsBoolAsSwitchCondition(int c
) {
16 switch ((bool)c
) { // expected-warning {{switch condition has boolean value}}
21 switch ((int)(bool)c
) { // no-warning
27 int *&castToIntPtrLValueRef(char *p
) {
28 return (int *&)*(int *)p
;
30 bool testCastToIntPtrLValueRef(char *p
, int *s
) {
31 return castToIntPtrLValueRef(p
) != s
; // no-crash
34 int *&&castToIntPtrRValueRef(char *p
) {
35 return (int *&&)*(int *)p
;
37 bool testCastToIntPtrRValueRef(char *p
, int *s
) {
38 return castToIntPtrRValueRef(p
) != s
; // no-crash
41 bool retrievePointerFromBoolean(int *p
) {
43 *reinterpret_cast<int **>(&q
) = p
;
47 namespace base_to_derived
{
49 struct B
: public A
{};
54 clang_analyzer_eval(a2
== a
); // expected-warning{{TRUE}}
58 namespace base_to_derived_double_inheritance
{
70 clang_analyzer_eval(c
->x
); // expected-warning{{UNKNOWN}}
71 clang_analyzer_eval(c
->y
); // expected-warning{{TRUE}}
73 } // namespace base_to_derived_double_inheritance
75 namespace base_to_derived_opaque_class
{
78 operator int() { return !x
; } // no-crash
82 typedef struct Opaque
*OpaqueRef
;
83 typedef void *VeryOpaqueRef
;
87 int getNotInt() { return NI
; }
91 class SubTransparent
: public Transparent
{};
93 SubTransparent
*castToDerived(Transparent
*TRef
) {
94 return (SubTransparent
*)TRef
;
97 void foo(OpaqueRef ORef
) {
98 castToDerived(reinterpret_cast<Transparent
*>(ORef
))->getNotInt();
101 void foo(VeryOpaqueRef ORef
) {
102 castToDerived(reinterpret_cast<Transparent
*>(ORef
))->getNotInt();
104 } // namespace base_to_derived_opaque_class
106 namespace bool_to_nullptr
{
113 for (int i
= 0; i
< 2; ++i
)
114 (void)(s
.a
[i
] != nullptr); // no-crash
116 } // namespace bool_to_nullptr