[cfe-commits] r115713 - in /cfe/trunk: lib/Sema/SemaType.cpp test/Sema/typeof-use-deprecated.c

John McCall rjmccall at apple.com
Tue Oct 5 17:34:13 PDT 2010


On Oct 5, 2010, at 5:26 PM, jahanian wrote:

> 
> On Oct 5, 2010, at 5:19 PM, John McCall wrote:
> 
>> 
>> On Oct 5, 2010, at 5:03 PM, jahanian wrote:
>> 
>>> 
>>> On Oct 5, 2010, at 4:52 PM, John McCall wrote:
>>> 
>>>> On Oct 5, 2010, at 4:24 PM, Fariborz Jahanian wrote:
>>>>> Author: fjahanian
>>>>> Date: Tue Oct  5 18:24:00 2010
>>>>> New Revision: 115713
>>>>> 
>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=115713&view=rev
>>>>> Log:
>>>>> Issue deprecated warning when typeof uses an
>>>>> expression of deprecated type.
>>>> 
>>>> This seems strange to me;  deprecation warnings are usually based on how something is spelled, not what it actually resolves to.  For example, even if a record type is deprecated, you can still make variables of that type if you have a non-deprecated typedef for it.  So if the variable itself isn't deprecated, I'm not sure why getting its type with typeof is more suspect than any other use.  Is there a specific use case motivating this?
>>> 
>>> typeof is a gcc extension and I followed gcc's behavior. I guess it is because typeof is really a replacement for using
>>> the deprecated type directly. But I don't know more than that.
>> 
>> Okay.
>> 
>>>> There are a lot of subsidiary questions here, like whether we should warn in the following test cases:
>>>> deprecated_type *a; typeof(*a) b;  // we now warn about this
>>>> deprecated_type *a; typeof(a) b;  // but not about this
>>>> deprecated_typedef a; typeof(a) b;  // or this
>>> 
>>> gcc issues warnings on these but not for this, for example:
>>> 
>>>> deprecated_type a[10]; typeof (a) b;
>> 
>> Actually, as far as I can tell you've implemented the exact condition that gcc uses:  it warns if the expression has a deprecated record or enum type, discarding typedefs and not looking through pointers/arrays/whatever.
>> 
>>> So, I would say gcc's behavior is not consistent (I have access to 4.2 only though).
>>> But, I think we should warn in all cases (if we do for typeof ).
>> 
>> I agree that if we want to warn here, we should at least warn about deprecated typedefs.  But my preference would be to not warn here at all.
> 
> Agreed. Actually, gcc does that too (please see my followup email).

I don't see this at all.  gcc seems to look through typedefs and warn based on the underlying type's deprecatedness, unfortunately using the name of the typedef.

So this typeof produces a warning (misleadingly talking about 'bar'):
  struct foo { int x; } __attribute__((deprecated));
  typedef struct foo bar __attribute__((deprecated));
  bar x;
  int main() { typeof(x) y; }

But this one doesn't:
  struct foo { int x; };
  typedef struct foo bar __attribute__((deprecated));
  bar x;
  int main() { typeof(x) y; }

John.



More information about the cfe-commits mailing list