[llvm-dev] Query about Clang Static Analyzer behaviour

Deep Majumder via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 19 00:46:27 PST 2021


Hi everyone,
The following is a code from a test in the Clang Static Analyzer
(clang/test/Analysis/pointer-to-member.cpp): Why are the last two
statements expected to produce a warning?
struct B {
int f;
};
struct L1 : public B { };
struct R1 : public B { };
struct M : public L1, R1 { };
struct L2 : public M { };
struct R2 : public M { };
struct D2 : public L2, R2 { };

void diamond() {
M m;

static_cast<L1 *>(&m)->f = 7;
static_cast<R1 *>(&m)->f = 16;

int L1::* pl1 = &B::f;
int M::* pm_via_l1 = pl1;

int R1::* pr1 = &B::f;
int M::* pm_via_r1 = pr1;

clang_analyzer_eval(m.*(pm_via_l1) == 7); // expected-warning {{TRUE}}
clang_analyzer_eval(m.*(pm_via_r1) == 16); // expected-warning {{TRUE}}
}
Warm Regards,
Deep
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210119/20e36cb2/attachment.html>


More information about the llvm-dev mailing list