Skip to content

C++: Suppress ExprHasNoEffect on template code#2399

Merged
geoffw0 merged 1 commit into
github:masterfrom
jbj:ExprHasNoEffect-templates
Nov 21, 2019
Merged

C++: Suppress ExprHasNoEffect on template code#2399
geoffw0 merged 1 commit into
github:masterfrom
jbj:ExprHasNoEffect-templates

Conversation

@jbj

@jbj jbj commented Nov 20, 2019

Copy link
Copy Markdown
Contributor

@jbj jbj added the C++ label Nov 20, 2019
@jbj jbj requested a review from a team as a code owner November 20, 2019 14:13

@geoffw0 geoffw0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a quick look, looks sensible but I haven't thought very hard about it yet.

not peivc.getEnclosingFunction().isDefaulted() and
not exists(Macro m | peivc = m.getAnInvocation().getAnExpandedElement()) and
not peivc.isFromTemplateInstantiation(_) and
not peivc.isFromUninstantiatedTemplate(_) and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised we didn't already have this exception, given the number of other exceptions!

@@ -84,6 +84,7 @@ where
not peivc.getEnclosingFunction().isDefaulted() and
not exists(Macro m | peivc = m.getAnInvocation().getAnExpandedElement()) and
not peivc.isFromTemplateInstantiation(_) and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line still contributing positively?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - it handles cases where a call in a void context has a pure target in some instantiations and a target with side effects in other instantiations. Ideally we'd handle that with a forall, but I don't think we have any way of matching the corresponding elements in different instantiations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unusual thing here is that we're excluding both uninstantiated templates and instantiated templates. That means we're excluding all template code. We usually exclude either one or the other, but in this case there has been false positives in both types of code.

We could try something elaborate like counting the number of potential alerts in the template and its instantiations and reporting an alert only if those counts match, but I don't think this query is important enough for us to spend time on that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds like this is a reasonable solution then.

@geoffw0 geoffw0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@geoffw0 geoffw0 merged commit 676e8a2 into github:master Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LGTM.com - false positive

3 participants