Community
Participate
Working Groups
There's no warning in this case: int foo(int a) { int* ptr = 0; ptr = &a; if (ptr) { std::cout << "hello" << std::endl; } else { return 1; } } The problem is the evaluation of variable ptr via ValueFactory. The evaluation is performed only on initial value : /** * Extract a value off a binding. */ private static IValue evaluateBinding(IBinding b) { ..... if (b instanceof IVariable) { value = ((IVariable) b).getInitialValue(); .....
New Gerrit change created: https://git.eclipse.org/r/139694
This is the same issue as bug 476388. The discussion in the patch there is probably useful background.
You are right, this is a duplicate. I didn't understand the final patch of that bug. It seems the initial value is still taken into account z regardless the condition of empty condition statements, the patch 14 doesn't add anything. The basic problem is the lack of a proper data flow analysis, without tracking variable uses we will have always false negative/positive. It's just a matter to understand what's better at the moment. However my patch is lesser "invasive" than the other patch, with the exception of cfg other code is not affected.
(In reply to Marco Stornelli from comment #3) > The basic problem is the lack of a proper data flow analysis, > without tracking variable uses we will have always false negative/positive. Agreed. > It's just a matter to understand what's better at the moment. In the review of https://git.eclipse.org/r/#/c/54358/, Elena was of the opinion that, for purposes of building the control flow graph, we should always use the initial value of the variable, even if it's not const. I am not sure whether she has changed her opinion since then. I cc'd her so she can chime in here.