[cfe-dev] -Wunreachable-code and templates

Jim Lawson jrloogle at gmail.com
Wed Nov 30 20:53:47 PST 2011


<kremene> Date: Wed, 30 Nov 2011 18:33:39 -0800
> From: David Blaikie
> Subject: Re: [cfe-dev] -Wunreachable-code and templates
> To: kremenek
> Cc: cfe-dev Developers <cfe-dev at cs.uiuc.edu>
> Message-ID:
>        <CAENS6EuPHirDBA3pJC553_USeTdsOX24zSMpRaf21E8VAS734Q at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Wed, Nov 30, 2011 at 1:26 PM, Ted Kremenek  wrote:
>> On Nov 30, 2011, at 11:54 AM, Ted Kremenek wrote:
>>
>> > Realistically, unless we really want to be super clever here, the most
>> > immediate solution to making -Wunreachable-code useful in the presence of
>> > templates is to simply have it skip templates entirely.
>>
>> In the spirit of improving the utility of the warning, I have gone and done
>> this in?r145520. ?If we come up with a better solution, we can certainly
>> change this. ?I believe the general solution, if one exists, will be very
>> complex.
>
> Thanks Ted - I tend to agree once we got to those examples of
> conditionally unreachable code that it appears to be a hard problem. I
> did check gcc's behavior, but it seems they gave up on this warning
> entirely around 4.3-4.4 (because their implementation was based on
> their optimizations & fraught with many more problems than just
> templates, by the sounds of it) so we're not missing any GCC parity
> here by not checking templates.
>
> Slightly related/minor tidyup - should the isType/ValueDependent
> checks in tryEvaluate/tryEvaluateBool be removed (and possibly
> replaced with assertions) as they don't seem to do anything - we
> weren't visiting dependent contexts previously nor are we now.
>
> - David
>

I think this is the only reasonable solution (having
-Wunreachable-code skip templates entirely).

Templates are used to generate code. Subjecting them to
-Wunreachable-code implies that all the potentially generated code has
to exist in all instantiations.

I would love to have templates that generate no code in some instantiations.



More information about the cfe-dev mailing list