Kean Johnston <[EMAIL PROTECTED]> writes:

>> A common situation would be:
>>      if (condition) {
>>              flag = 1
>>              msg = "Hello World";
>>      } else
>>              flag = 0;                       [1]
>>      ...
>>      if (flag)
>>              printf ("I say, %s\n", msg);    [2]
>> Point [1] is where I "fail" to init 'msg', point [2] is where I
>> use it. I know that the program is safe, and if the flow analysis
>> can relate 'flag' and 'msg' then the warning would go away.
>> Which one would we want listed in the proposed new warning, 1 or 2?
>
> Definately 2. I wont say it is *impossible*, but I think
> it is asking way too much of the compiler to warn about 1.
> It implies a level of understanding of the flow of the
> program that is completely unrealistic. However, warning at
> 2 should be trivial.

Unfortunately, it isn't. This warning happens very late in the
processing, after a lot of mangling has been done. Take:

inline int f(int x) {
    return x + 1;               // 1
}

int g(int a) {
    int b;
    if (a)
        b = 0;
    return f(b);                // 2
}

You probably want a warning at (2). However, that is long gone and has
been replaced by the code from (1), so at best we could warn at (1),
which would be pretty confusing. (Hmm. Mainline doesn't seem to warn
at all here, but I think this is already somewhere in bugzilla...)

-- 
        Falk

Reply via email to