Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S4070: False positive with combined values #809

Closed
Chelaris182 opened this issue Oct 6, 2017 · 3 comments
Closed

Fix S4070: False positive with combined values #809

Chelaris182 opened this issue Oct 6, 2017 · 3 comments
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@Chelaris182
Copy link
Contributor

Chelaris182 commented Oct 6, 2017

The current implementation of the rule raises violation of S4070 for the following code:

    [Flags]
    public enum Foo
    {
        N1 = 1,
        N2 = 2,
        N3 = N1 | N2,
        N4 = 4,
        N5 = N4 | N1
    }

If you remove N5, the violation goes away.

@michalb-sonar michalb-sonar changed the title S4070 FP violations Fix S4070: False positive Oct 9, 2017
@michalb-sonar michalb-sonar added Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. labels Oct 9, 2017
@michalb-sonar
Copy link
Contributor

Thanks for report and sample code @Chelaris182. I was able to reproduce the problem, we'll fix that.

@Chelaris182
Copy link
Contributor Author

Looking at the rule code I also came up with a false negative case:

    [Flags]
    public enum Options
    {
        N1 = 1,
        N2 = 2,
        N3 = N1 | N2,
        N5 = 5
    }

@michalb-sonar
Copy link
Contributor

Good catch @Chelaris182!

@michalb-sonar michalb-sonar added the Type: False Negative Rule is NOT triggered when it should be. label Oct 9, 2017
@michalb-sonar michalb-sonar added this to the 6.6 milestone Oct 16, 2017
@Evangelink Evangelink removed the Type: False Negative Rule is NOT triggered when it should be. label Oct 18, 2017
@Evangelink Evangelink changed the title Fix S4070: False positive Fix S4070: False positive with flag values Nov 7, 2017
@Evangelink Evangelink changed the title Fix S4070: False positive with flag values Fix S4070: False positive with combined values Nov 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

3 participants