[Patch] Disable -Wtaulological-compare for substituted template types

Richard Trieu rtrieu at google.com
Thu Oct 31 17:52:27 PDT 2013

On Thu, Oct 31, 2013 at 4:25 PM, David Blaikie <dblaikie at gmail.com> wrote:

> On Thu, Oct 31, 2013 at 4:12 PM, Richard Trieu <rtrieu at google.com> wrote:
>> On Thu, Oct 31, 2013 at 2:44 PM, Richard Trieu <rtrieu at google.com> wrote:
>>> On Thu, Oct 31, 2013 at 10:35 AM, David Blaikie <dblaikie at gmail.com>wrote:
>>>> Looks pretty reasonable - but are these two separate code changes, or
>>>> do they interrelate in some way? If they're separate changes that can have
>>>> separate test cases, it'd be nice to commit them each in their on commit
>>>> just for clarity.
>>> Yes, I can separate them into two pieces when I submit them.
>>>> Have you considered/plan to look at non-type template parameters?
>>>> template<int Num>
>>>> bool greater(unsigned Val) {
>>>>   return Val >= Num;
>>>> }
>>>> ... greater<0>(42); ...
>>>> I'm not sure if this tickles the same kind of problem or not - but
>>>> might be worth checking.
>>>> I haven't seen this case yet, but I would say it is good to include
>>> this test case too.   I think changing the check to an instantiation
>>> dependency check would allow it to catch this case as well.
>> I spoke too soon.  The information about non-template types doesn't
>> persist up the AST tree so it isn't as easily retrievable as the
>> substituted template types.  For a simple case like your example, it would
>> be simple to check for a substituted expression in the operand.  For a more
>> complicated constant expression, an AST visitor would be needed, or the
>> function that computes the constant value would need to pass this
>> information back.  I'll stick with template types for now.
> Could we just restrict these warnings to only be done on template
> patterns, not template specializations? (I know Ted's had some concern
> about doing work on template patterns in the past because he believed that
> might create too much work analyzing templates that are never instantiated,
> though)
> Then we'd get constants and types where they were available, and not
> before.
I think that would be possible and a cleaner way of approaching this.
 Currently, Clang warns in both template patters and specializations.  That
means if you have :

template<int Num>
bool greater(unsigned Val) {
  return Val >= 0;

... greater<0>(42); ...
... greater<1>(42); ...
... greater<2>(42); ...

There would be four warnings on the return line.  Ignoring the three
warnings in the specializations and only showing the one from the template
pattern would be best on cutting down the noise.

>>>> On Wed, Oct 30, 2013 at 8:17 PM, Richard Trieu <rtrieu at google.com>wrote:
>>>>> This patch turns off the tautological compare warnings when one of the
>>>>> operands is a template parameter type.  There's not an easy way to correct
>>>>> the code or silence this warning so this way seemed to be the best
>>>>> solution.  Anyone have any thoughts on altering the behavior of this
>>>>> warning?
>>>>> _______________________________________________
>>>>> cfe-commits mailing list
>>>>> cfe-commits at cs.uiuc.edu
>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131031/f0df5c3a/attachment.html>

More information about the cfe-commits mailing list