C/C++ PATCH to allow deprecating enum values (PR c/47043)

Ed Smith-Rowland 3dw4rd@verizon.net
Thu May 7 14:22:00 GMT 2015


On 05/07/2015 09:59 AM, Marek Polacek wrote:
> On Wed, May 06, 2015 at 11:17:20PM -0400, Ed Smith-Rowland wrote:
>> In addition to a PR this is 1/2 of a C=+17 feature. (The other half - really
>> a separate thing - is attributes on namespaces).
> Ah, nice, I wasn't aware.  For the record, this is
> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4266.html>.
>   
>> I wonder if we should pedwarn for < C++17?
>> Or it could be just an extension for < C++17 - I guess that would match with
>> clang.
>   
> Yeah, it is meant as a GNU extension.  (clang supports this extension for
> several years already.)  I'd rather let Jason decide what to do wrt C++17.
>   
>> @@ -3651,11 +3651,6 @@ finish_id_expression (tree id_expression,
>>       }
>>       }
>>
>> -  /* Handle references (c++/56130).  */
>> -  tree t = REFERENCE_REF_P (decl) ? TREE_OPERAND (decl, 0) : decl;
>> -  if (TREE_DEPRECATED (t))
>> -    warn_deprecated_use (t, NULL_TREE);
>> -
>>     return decl;
>>   }
>>
>> Why did this bit get removed?
> This hunk got added in r201906 to address c++/56130 - we didn't warn for
> deprecated references:
>
> int g_nn;
> int& g_n __attribute__((deprecated)) = g_nn;
>
> int main()
> {
>      g_n = 1;
> }
>
> But then Jason added warn_deprecated_use to mark_used in r217677 and we
> warned twice.  So I figured the warning in finish_id_expression isn't
> needed anymore.
>   
>> Do we handle enums in template specializations?
> Not sure, could you provide a testcase?  Thanks,
>
> 	Marek
>
Instead of NULL_TREE in pt.c I grabbed the attrs.

       /* Actually build the enumerator itself.  */
       build_enumerator
     (DECL_NAME (decl), value, newtag, DECL_ATTRIBUTES (decl),
      DECL_SOURCE_LOCATION (decl));

Seems to work.

Also, I haven't tested the testcase in terms of the pattern matching of 
the error.  Tweak it if necessary.

Thanks for this.

Ed


-------------- next part --------------
A non-text attachment was scrubbed...
Name: attributes-enum-2.C
Type: text/x-c++src
Size: 427 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20150507/be1e5e3f/attachment.bin>


More information about the Gcc-patches mailing list