<div dir="ltr"><div class="gmail_extra">It would be better to have the warning and no-warning cases for typeid next to each other. Otherwise, LGTM, thanks!</div><div class="gmail_extra"><br></div><div class="gmail_extra">Does this also fix the same issue for -Wunused-comparison?</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 16, 2014 at 11:58 AM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Patch attached with more test cases; the typeid case you were<br>
concerned is also addressed in this patch.<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Thu, Oct 16, 2014 at 2:27 PM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
> On Thu, Oct 16, 2014 at 11:28 AM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
>> On Thu, Oct 16, 2014 at 10:23 AM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
>>> On Thu, Oct 16, 2014 at 9:05 AM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
>>>> On Wed, Oct 15, 2014 at 10:33 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
>>>>> Does this still warn on cases like:<br>
>>>>><br>
>>>>>   typeid(f(), g());<br>
>>>>><br>
>>>>> where we don't know we've got an evaluated operand until after we've<br>
>>>>> finished parsing it?<br>
>>>>><br>
>>>>> ... Hmm, we don't seem to get any warning on that case right now. =( Might<br>
>>>>> be worth someone looking into that, maybe there are other cases we're<br>
>>>>> missing.<br>
>>><br>
>>> I'd like to make sure my understanding is correct. Given:<br>
>>><br>
>>> #include <typeinfo><br>
>>><br>
>>> struct B {<br>
>>>   virtual int f();<br>
>>> };<br>
>>><br>
>>> struct D : B {<br>
>>>   virtual int f();<br>
>>> };<br>
>>><br>
>>> B *h() __attribute__((warn_unused_result));<br>
>>> B *h() { return new D; }<br>
>>><br>
>>> int f() __attribute__((warn_unused_result));<br>
>>> int g();<br>
>>><br>
>>> int main() {<br>
>>>   const auto &t1 = typeid(f(), g()); // Should not warn; unevaluated context?<br>
>>>   const auto &t2 = typeid(h(), g()); // Should warn; evaluated context?<br>
>>> }<br>
>>><br>
>>> Is that the test case we're looking at for the typeid portion of this?<br>
>><br>
>> I don't think it is. The result of h(), g() is still int, which is not<br>
>> a glvalue of polymorphic type. I'm struggling to think of a way in<br>
>> which I should trigger the unused result warning in the potentially<br>
>> evaluated case that wouldn't count as a use.<br>
><br>
> Okay, I just needed to eat lunch to figure this out. ;-)<br>
><br>
> #include <typeinfo><br>
><br>
> struct B {<br>
>   virtual void f();<br>
> };<br>
><br>
> struct D : B {<br>
>   void f() override;<br>
> };<br>
><br>
> struct C {};<br>
><br>
> int f() __attribute__((warn_unused_result));<br>
><br>
> int main() {<br>
>   D d;<br>
>   C c;<br>
>   (void)typeid(f(), d); // Warn about unused result because d is a<br>
> glvalue of polymorphic type<br>
>   (void)typeid(f(), c); // Do not warn about unused result, because c<br>
> is not a polymorphic type<br>
> }<br>
><br>
> ~Aaron<br>
</div></div></blockquote></div><br></div></div>