This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Q.: inconsistent (?) warnings about functions called through non-compatible types
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Godmar Back <godmar at gmail dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Sun, 29 Mar 2015 22:33:12 +0100
- Subject: Re: Q.: inconsistent (?) warnings about functions called through non-compatible types
- Authentication-results: sourceware.org; auth=none
- References: <CAB4+JY+wKi2YniOOJLydB_Q6QHSE4f9i7x-Ld+dO6X0V9hApHg at mail dot gmail dot com>
On 29 March 2015 at 19:32, Godmar Back wrote:
> Why does assigning boolFunctionThatReturnsFalse to a variable f after
> the cast, instead of directly dereferencing it, silence the compiler's
> warnings?
Because the cast itself is OK, and the call that results in undefined
behaviour is separate from the cast. The compiler is not smart enough
to see that in the call f() the value of f is not really an
intFunction.
In the second case the compiler knows for a fact that the function
being called does not have the correct type, because the cast and the
call are part of the same expression.