Opened 3 years ago
Last modified 5 months ago
#10733 new defect
False positive passedByValue for function pointer with using-declaration
| Reported by: | ptomato | Owned by: | noone |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | False positive | Version: | |
| Keywords: | passedByValue simplifyusing | Cc: |
Description
bug.cpp:
#include <vector> struct S { std::vector<int> v; using F = void (*)(); void func(F f); }; void S::func(S::F f) {}
Output:
cppcheck bug.cpp --enable=performance
Checking bug.cpp ...
bug.cpp:7:19: performance: Function parameter 'f' should be passed by const reference. [passedByValue]
void S::func(S::F f) {}
^
F should not be marked as being passed by value, because it is a pointer.
Any of the following changes will make this error disappear:
- Remove the
vmember or replace it by a member with a POD type such asint. (Butstd::deque<int> vstill shows the error, for example) - Write out the function pointer type instead of a
using-declaration. - Move the body of
funcinline in the class declaration. - Change the type alias
Fto a data pointer, such asvoid*.
Observed with cppcheck 2.6.
Change History (4)
comment:1 by , 3 years ago
comment:3 by , 3 years ago
| Keywords: | passedByValue simplifyusing added |
|---|
Variable f doesn't have the pointer flag.
comment:4 by , 5 months ago
This started with 2.4 and has been bisected to https://github.com/danmar/cppcheck/commit/3c6fae37e439c2b264d1712e5a6d45c6878be276.
It was also previously reported from 1.75 to 1.90.
Note:
See TracTickets
for help on using tickets.
There's also no warning with
typedef void (*F)();.