Are there any static analysis tools that check for Rule of 3 (or Rule of 5 C++11) [closed]
Asked Answered
M

2

3

I am currently working on a codebase that is built on a foundation of sand.

There are numerous classes in supposedly tested libraries that violate the "Rule of 3". Most declare a non-trivial destructor, but are missing either a copy constructor or assignment operator.

Are there any compiler flags (gcc) or static analysis tools that warn when a class violates the rule of 3?

Currently we are using Coverity with GCC version 4.4.

Mythify answered 7/5, 2013 at 15:57 Comment(2)
Could you be more specific ? Maybe an example could help...Pneumatograph
@Andrey Cpp - Example sentMythify
K
0

Coverity has. We use version 6.5. There is a checker MISSING_COPY_OR_ASSIGN.

Krieger answered 24/5, 2013 at 4:43 Comment(3)
This rule is not enabled with Coverity by default (might be considered to be a false positive). We have now enabled it and have highlighted a number of issues.Mythify
@Mythify Please check --rule option. It enables all these: ASSIGN_NOT_RETURNING_STAR_THIS, COPY_WITHOUT_ASSIGN, MISSING_COPY_OR_ASSIGN, SELF_ASSIGN. Coverity has a nice docs @ server:8080/docs/en/index.html. Port can be different, up to config.Krieger
@Mythify Default set is very conservative. I ran 130 out of 150 checkers that I found every night with all department sources in a single build. With very parallel build it takes only 4 hours. I sorted all defects into 4 levels to treat them separately. I can share my classification.Krieger
N
0

C++test from Parasoft (commercial tool) has a rule (MRM-40) that covers "copy and destroy consistently" that looks like it would help you. Basically it says if you define any of the copy constructor, copy assignment operator, or destructor, you might need to define one or both of the others.

More info at http://www.parasoft.com/jsp/products/cpptest.jsp

Natty answered 8/5, 2013 at 20:3 Comment(0)
K
0

Coverity has. We use version 6.5. There is a checker MISSING_COPY_OR_ASSIGN.

Krieger answered 24/5, 2013 at 4:43 Comment(3)
This rule is not enabled with Coverity by default (might be considered to be a false positive). We have now enabled it and have highlighted a number of issues.Mythify
@Mythify Please check --rule option. It enables all these: ASSIGN_NOT_RETURNING_STAR_THIS, COPY_WITHOUT_ASSIGN, MISSING_COPY_OR_ASSIGN, SELF_ASSIGN. Coverity has a nice docs @ server:8080/docs/en/index.html. Port can be different, up to config.Krieger
@Mythify Default set is very conservative. I ran 130 out of 150 checkers that I found every night with all department sources in a single build. With very parallel build it takes only 4 hours. I sorted all defects into 4 levels to treat them separately. I can share my classification.Krieger

© 2022 - 2024 — McMap. All rights reserved.