Fix confusion between function call and variable declaration
I'm at the point where I'd like some feedback on this (incomplete) solution to https://trac.cppcheck.net/ticket/9960
In a nutshell, the problem is that cppcheck sometimes does a poor job of distinguishing function calls from variable declarations. There are some cases where the two are indistinguishable because the declarations of the identifiers involved are hidden from cppcheck but my initial concern is the case where they are available. A simple example is that foo(bar); is a function call if foo is a function but a variable declaration if foo is a type (even if bar is a variable name and foo has a constructor that will accept bar). The example I encountered in real code was more like
void foo() {
std::vector<int*> a(10); //In the real code this would have been initialized somehow
for (int i = 0; i < 10; i++)
bar(*a[4]); //This was misinterpreted as a variable declaration issuing a warning about shadowing 'a'
}
My solution is to, when determining whether a token is part of a variable declarations, check whether the "type" is actually already known to be a function. This is somewhat complicated by the fact that at the point where we process variables we have not fully completed processing functions so a lot of data I would like to be able to use is not yet available.
@danmar could I get some input on this please?
yes. Sorry for the delay.. it just seems complex.. thanks a lot for working on this!