[PATCHv3] implement -Wold-style-cast

Jordan Rose jordan_rose at apple.com
Mon Dec 2 09:37:52 PST 2013


On Nov 26, 2013, at 19:22 , Alp Toker <alp at nuanti.com> wrote:

> On 26/11/2013 18:51, Ondřej Hošek wrote:
>> Hi everyone,
>> 
>> On Tue, Nov 26, 2013 at 9:37 AM, Alp Toker <alp at nuanti.com> wrote:
>>> GCC doesn't warn on (void) casts.
>>> 
>>> The patch should be fixed to handle these cases too:
>>> 
>>> (void)x; // no warning
>>> (long)x; // warning
>>> 
>>> The necessary checks can be done in Parse, but might be slightly easier /
>>> future-proof handle them in Sema.
>> Thanks for the feedback; I have updated the patch accordingly.
> 
> Hi Ondra,
> 
> This one is pretty much what we want, except that the check needs to be moved up to ActOnCastExpr() to avoid diagnosing template instantiations or skipping diags due to early returns.
> 
> I've made that change, padded out the tests with a few more cases like (void**)x; and typedef void VOID; which we now get right and landed in r195808.
> 
> Thanks!

A bit late to this, but please make sure we’re not warning on bridge casts in ARC/C++ mode:

id test(void *opaqueInput) {
	id someObjCObject = (__bridge id)opaqueInput;
	void *someCFObject = (__bridge_retained void *)someObjCObject;
	return (__bridge_transfer id)someCFObject;
}

We don’t currently have a way to write these in terms of C++ casts.

Jordan



More information about the cfe-commits mailing list