Summary: | clazy-function-args-by-value false positive when ref constructor arg is stored as ref in class | ||
---|---|---|---|
Product: | [Developer tools] clazy | Reporter: | Markus Enzenberger <markus.enzenberger> |
Component: | general | Assignee: | Sergio Martins <smartins> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | markus.enzenberger, smartins |
Priority: | NOR | ||
Version First Reported In: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Other | ||
OS: | Linux | ||
Latest Commit: | https://commits.kde.org/clazy/51ba8ddfaffbe0d15e5165b4d135d9a62749dd8f | Version Fixed In: | |
Sentry Crash Report: |
Description
Markus Enzenberger
2017-04-29 09:42:52 UTC
Forget the last sentence about the non-const-ref case, of course there is no optimization there. (In reply to markus.enzenberger from comment #0) > The following snippet creates a clazy-function-args-by-value warning even if > it is essential to use a reference since the class stores a copy of the > reference. If the user follows the recommendation by clazy, a bug is > intruduced in the code, which not every compiler will detect and warn about. Do you know which compilers actually warn about this ? I currently only have access to gcc and clang and they both do not warn if the reference argument is replaced by a value argument even if it obviously makes no sense to store a reference to a temporary. Git commit 64541809a9a98c6f16f80587baacb1ab7eeef381 by Sergio Martins. Committed on 18/09/2017 at 20:57. Pushed by smartins into branch '1.2'. function-args-by-value: Add unit-test for bug 379342 M +2 -1 tests/function-args-by-value/config.json M +6 -0 tests/function-args-by-value/main.cpp https://commits.kde.org/clazy/64541809a9a98c6f16f80587baacb1ab7eeef381 Git commit 51ba8ddfaffbe0d15e5165b4d135d9a62749dd8f by Sergio Martins. Committed on 18/09/2017 at 21:39. Pushed by smartins into branch '1.2'. function-args-by-value: Fix false positive When passing to a ctor that inits members by ref we must preserve the ref in the original param. M +23 -1 src/checks/level2/function-args-by-value.cpp A +12 -0 tests/function-args-by-value/bug379342.cpp [License: UNKNOWN] * A +1 -0 tests/function-args-by-value/bug379342.cpp.expected M +4 -2 tests/function-args-by-value/config.json M +0 -6 tests/function-args-by-value/main.cpp The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page. https://commits.kde.org/clazy/51ba8ddfaffbe0d15e5165b4d135d9a62749dd8f |