This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix up -Wdeprecated (PR c++/84222)
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 15 Mar 2018 13:24:48 -0400
- Subject: Re: [C++ PATCH] Fix up -Wdeprecated (PR c++/84222)
- References: <20180314222600.GM8577@tucnak> <CADzB+2nwKbJkcxTmKjOUOhx=EQWBSDRwtxupvK4bioLcgPeO3A@mail.gmail.com> <20180315080720.GO8577@tucnak>
On Thu, Mar 15, 2018 at 4:07 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Mar 14, 2018 at 08:44:48PM -0400, Jason Merrill wrote:
>> > --- gcc/cp/decl.c.jj 2018-03-14 09:44:55.744974946 +0100
>> > +++ gcc/cp/decl.c 2018-03-14 12:18:08.094012453 +0100
>> > @@ -10448,7 +10448,7 @@ grokdeclarator (const cp_declarator *dec
>> > suppress reports of deprecated items. */
>> > if (type && TREE_DEPRECATED (type)
>> > && deprecated_state != DEPRECATED_SUPPRESS)
>> > - warn_deprecated_use (type, NULL_TREE);
>> > + cp_warn_deprecated_use (type);
>> > if (type && TREE_CODE (type) == TYPE_DECL)
>> > {
>> > typedef_decl = type;
>> > @@ -10456,7 +10456,7 @@ grokdeclarator (const cp_declarator *dec
>> > if (TREE_DEPRECATED (type)
>> > && DECL_ARTIFICIAL (typedef_decl)
>> > && deprecated_state != DEPRECATED_SUPPRESS)
>> > - warn_deprecated_use (type, NULL_TREE);
>> > + cp_warn_deprecated_use (type);
>> > }
>> > /* No type at all: default to `int', and set DEFAULTED_INT
>> > because it was not a user-defined typedef. */
>> > @@ -11271,8 +11271,18 @@ grokdeclarator (const cp_declarator *dec
>> > explicitp = 2;
>> > }
>> >
>> > - arg_types = grokparms (declarator->u.function.parameters,
>> > - &parms);
>> > + tree pushed_scope = NULL_TREE;
>> > + if (funcdecl_p
>> > + && decl_context != FIELD
>> > + && inner_declarator->u.id.qualifying_scope
>> > + && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
>> > + pushed_scope
>> > + = push_scope (inner_declarator->u.id.qualifying_scope);
>>
>> Can't we use ctype here?
>
> Inside of classes ctype is non-NULL, but we don't need to push anything,
> current_class_type is already the class we care about.
> That's the
> tree ctype = current_class_type;
> on line 10130. Then we have this
> for (id_declarator = declarator;
> id_declarator;
> id_declarator = id_declarator->declarator)
> loop, where for cdk_id at line 10242 it tweaks ctype:
> else if (TYPE_P (qualifying_scope))
> {
> ctype = qualifying_scope;
> if (!MAYBE_CLASS_TYPE_P (ctype))
> {
> error ("%q#T is not a class or a namespace", ctype);
> ctype = NULL_TREE;
> }
> and indeed for the cases I care about (out of class method definitions)
> ctype is set to non-NULL here. But then at line 10542 it is cleared again:
> ctype = NULL_TREE;
>
> and at 11176:
> if (ctype == NULL_TREE
> && decl_context == FIELD
> && funcdecl_p
> && friendp == 0)
> ctype = current_class_type;
> set only for selected in-class definitions, and then tested and used a couple of
> times. And that is the state we call grokparms with.
> Only later at line 11529 it is set again:
> if (declarator
> && declarator->kind == cdk_id
> && declarator->u.id.qualifying_scope
> && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
> {
> ctype = declarator->u.id.qualifying_scope;
> ctype = TYPE_MAIN_VARIANT (ctype);
> So, if I were to use some variable without really changing the behavior of
> the grokdeclarator massively, it would need to be a copy of ctype saved into
> another variable (how it should be named?) above line 10542. Given the
> TYPE_MAIN_VARIANT, I guess we should be using TYPE_MAIN_VARIANT somewhere
> too.
Wow, yeah, the use of ctype in grokdeclarator is pretty bizarre. Your
patch is OK.
Jason