Patch attached with more test cases; the typeid case you were
concerned is also addressed in this patch.

~Aaron

On Thu, Oct 16, 2014 at 2:27 PM, Aaron Ballman <[email protected]> wrote:
> On Thu, Oct 16, 2014 at 11:28 AM, Aaron Ballman <[email protected]> 
> wrote:
>> On Thu, Oct 16, 2014 at 10:23 AM, Aaron Ballman <[email protected]> 
>> wrote:
>>> On Thu, Oct 16, 2014 at 9:05 AM, Aaron Ballman <[email protected]> 
>>> wrote:
>>>> On Wed, Oct 15, 2014 at 10:33 PM, Richard Smith <[email protected]> 
>>>> wrote:
>>>>> Does this still warn on cases like:
>>>>>
>>>>>   typeid(f(), g());
>>>>>
>>>>> where we don't know we've got an evaluated operand until after we've
>>>>> finished parsing it?
>>>>>
>>>>> ... Hmm, we don't seem to get any warning on that case right now. =( Might
>>>>> be worth someone looking into that, maybe there are other cases we're
>>>>> missing.
>>>
>>> I'd like to make sure my understanding is correct. Given:
>>>
>>> #include <typeinfo>
>>>
>>> struct B {
>>>   virtual int f();
>>> };
>>>
>>> struct D : B {
>>>   virtual int f();
>>> };
>>>
>>> B *h() __attribute__((warn_unused_result));
>>> B *h() { return new D; }
>>>
>>> int f() __attribute__((warn_unused_result));
>>> int g();
>>>
>>> int main() {
>>>   const auto &t1 = typeid(f(), g()); // Should not warn; unevaluated 
>>> context?
>>>   const auto &t2 = typeid(h(), g()); // Should warn; evaluated context?
>>> }
>>>
>>> Is that the test case we're looking at for the typeid portion of this?
>>
>> I don't think it is. The result of h(), g() is still int, which is not
>> a glvalue of polymorphic type. I'm struggling to think of a way in
>> which I should trigger the unused result warning in the potentially
>> evaluated case that wouldn't count as a use.
>
> Okay, I just needed to eat lunch to figure this out. ;-)
>
> #include <typeinfo>
>
> struct B {
>   virtual void f();
> };
>
> struct D : B {
>   void f() override;
> };
>
> struct C {};
>
> int f() __attribute__((warn_unused_result));
>
> int main() {
>   D d;
>   C c;
>   (void)typeid(f(), d); // Warn about unused result because d is a
> glvalue of polymorphic type
>   (void)typeid(f(), c); // Do not warn about unused result, because c
> is not a polymorphic type
> }
>
> ~Aaron

Attachment: warn_unused_v2.patch
Description: Binary data

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to