Skip to content

Fix false positive from issue 8612#1285

Merged
danmar merged 1 commit intocppcheck-opensource:masterfrom
pfultz2:fp-duplicate-assign-assign
Jun 9, 2018
Merged

Fix false positive from issue 8612#1285
danmar merged 1 commit intocppcheck-opensource:masterfrom
pfultz2:fp-duplicate-assign-assign

Conversation

@pfultz2
Copy link
Copy Markdown
Contributor

@pfultz2 pfultz2 commented Jun 9, 2018

This fixes the FP by not warning for duplicate assignment if both variables are assigned to each other later on:

struct P
{
    void func();
    bool operator==(const P&) const;
};
struct X
{
    P first;
    P second;
};
bool bar();
void baz(const P&);
void foo(const X& x)
{
    P current = x.first;
    P previous = x.first;
    while (true)
    {
        baz(current);
        if (bar() && previous == current)
        {
            current.func();
        }
        previous = current;
    }
}

@danmar danmar merged commit daacf27 into cppcheck-opensource:master Jun 9, 2018
@pfultz2 pfultz2 deleted the fp-duplicate-assign-assign branch May 19, 2019 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants