llvm-project/clang/test/Analysis/member-expr.cpp
Jordan Rose 62ac9ecadc [analyzer] Don't assert when combining using .* on a temporary.
While we don't model pointer-to-member operators yet (neither .* nor ->*),
CallAndMessageChecker still checks to make sure the 'this' object is not
null or undefined first. However, it also expects that the object should
always have a valid MemRegion, something that's generally important elsewhere
in the analyzer as well. Ensure this is true ahead of time, just like we do
for member access.

PR19531

llvm-svn: 207561
2014-04-29 17:08:12 +00:00

42 lines
869 B
C++

// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection %s -verify
void clang_analyzer_checkInlined(bool);
void clang_analyzer_eval(int);
namespace EnumsViaMemberExpr {
struct Foo {
enum E {
Bar = 1
};
};
void testEnumVal(Foo Baz) {
clang_analyzer_eval(Baz.Bar == Foo::Bar); // expected-warning{{TRUE}}
}
void testEnumRef(Foo &Baz) {
clang_analyzer_eval(Baz.Bar == Foo::Bar); // expected-warning{{TRUE}}
}
void testEnumPtr(Foo *Baz) {
clang_analyzer_eval(Baz->Bar == Foo::Bar); // expected-warning{{TRUE}}
}
}
namespace PR19531 {
struct A {
A() : x(0) {}
bool h() const;
int x;
};
struct B {
void g(bool (A::*mp_f)() const) {
// This used to trigger an assertion because the 'this' pointer is a
// temporary.
(A().*mp_f)();
}
void f() { g(&A::h); }
};
}