[PATCH] D52008: [analyzer] Handle forwarding reference better in ExprMutationAnalyzer.

Shuai Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 12 17:45:28 PDT 2018


shuaiwang created this revision.
shuaiwang added reviewers: lebedev.ri, JonasToth.
Herald added subscribers: cfe-commits, Szelethus, mikhail.ramalho, a.sidorin, szepet, xazax.hun.
Herald added a reviewer: george.karpenkov.

We used to treat an `Expr` mutated whenever it's passed as non-const
reference argument to a function. This results in false positives in
cases like this:

  int x;
  std::vector<int> v;
  v.emplace_back(x); // `x` is passed as non-const reference to `emplace_back`

In theory the false positives can be suppressed with
`v.emplace_back(std::as_const(x))` but that's considered overly verbose,
inconsistent with existing code and spammy as diags.

This diff handles such cases by following into the function definition
and see whether the argument is mutated inside.


Repository:
  rC Clang

https://reviews.llvm.org/D52008

Files:
  include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  lib/Analysis/ExprMutationAnalyzer.cpp
  unittests/Analysis/ExprMutationAnalyzerTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52008.165189.patch
Type: text/x-patch
Size: 10384 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180913/418840ba/attachment.bin>


More information about the cfe-commits mailing list