public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Dodji Seketeli <dodji@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	       Benjamin De Kosnik <bkoz@redhat.com>
Subject: Re: [C++ PATCH] PR c++/45114 - Support alias templates
Date: Thu, 27 Oct 2011 22:40:00 -0000	[thread overview]
Message-ID: <4EA9CB03.5060708@redhat.com> (raw)
In-Reply-To: <m34nyuz1vt.fsf@redhat.com>

On 10/27/2011 03:10 PM, Dodji Seketeli wrote:
> +/* Setter for the TYPE_DECL_ALIAS_P proprety above.  */
> +#define SET_TYPE_DECL_ALIAS_P(NODE, VAL)               \
> +  (DECL_LANG_FLAG_6 (TYPE_DECL_CHECK (NODE)) = (VAL))

This seems unnecessary.

> +#define TYPE_DECL_NAMES_ALIAS_TEMPLATE_P(NODE)                         \
> +  (TYPE_DECL_ALIAS_P (NODE)                                            \
> +   && DECL_LANG_SPECIFIC (NODE)                                                \
> +   && DECL_TI_TEMPLATE (NODE)                                          \
> +   && same_type_p (TREE_TYPE (NODE), TREE_TYPE (DECL_TI_TEMPLATE (NODE))))

I don't think same_type_p is the test you want here, as it ignores 
typedefs.  How about

   DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (NODE)) == (NODE)

?

> +#define TYPE_ALIAS_P(NODE) \
> +  (TYPE_P (NODE) \
> +   && DECL_LANG_SPECIFIC (TYPE_NAME (NODE))    \
> +   && TYPE_DECL_ALIAS_P (TYPE_NAME (NODE)))

Why check DECL_LANG_SPECIFIC?

> +      /*If T is a specialization of an alias template, then we don't
> +       want to take this 'if' branch; we want to print it as if it
> +       was a specialization of class template.  */

I think we want to handle them specially within this if.

> -      else if (same_type_p (t, TREE_TYPE (decl)))
> +      else if (same_type_p (t, TREE_TYPE (decl))
> +              && /* If T is the type of an alias template then we
> +                    want to let dump_decl print it like an alias
> +                    template.  */
> +              TYPE_DECL_NAMES_ALIAS_TEMPLATE_P (decl))

This change restricts the existing test to only apply to alias templates.

Also, I would think we would want to handle the uninstantiated alias the 
same as instantiations.

You need some tests for printing of aliases in error messages.  Only one 
of the current tests prints an alias:

> /home/jason/gt/gcc/testsuite/g++.dg/cpp0x/alias-decl-1.C:5:26: error: partial specialization of alias template 'using AA0 = struct A0<int, T>'

This should have the template header.  So here:

 > +      if (DECL_ALIAS_TEMPLATE_P (TI_TEMPLATE (get_template_info 
(type))))
 > +       {
 > +         error ("partial specialization of alias template %qD",
 > +                TYPE_NAME (type));
 > +         return error_mark_node;
 > +       }

We should pass the template to error, rather than the instantiation. 
But when I try that I see that it prints

  template<class T, class U> struct AA0<T, U>

instead, so more fixing is needed.

> +  else if (DECL_ALIAS_TEMPLATE_P (t))
> +    {
> +      tree tmpl;
> +      result = get_aliased_type (DECL_TEMPLATE_RESULT (t));
> +      tmpl = TI_TEMPLATE (get_template_info (result));
> +      /* If RESULT is just the naming of TMPL, return TMPL.  */
> +      if (same_type_p (result,
> +                      TREE_TYPE (DECL_TEMPLATE_RESULT (tmpl))))
> +       result = tmpl;
> +    }

What is this trying to achieve?  When we pass in a template, sometimes 
it returns a type and sometimes a template?  That seems odd.

> +      else
> +       /* Strip template aliases from TEMPLATE_DECL nodes,
> +          similarly to what is done by
> +          canonicalize_type_argument for types above.  */
> +       val = strip_alias (val);

I don't think this is right.  Alias templates are never deduced, but 
that doesn't seem to mean that they can't be used as template template 
arguments.  Both clang and EDG accept this testcase:

template <class T, class U> struct same;
template <class T> struct same<T,T> {};

template <class T> using Ptr = T*;
template <template <class> class T> struct A {
   template <class U> using X = T<U>;
};
same<A<Ptr>::X<int>,int*> s;

> +               if (ctx == DECL_CONTEXT (t)
> +                   && (TREE_CODE (t) != TYPE_DECL
> +                       /* ... unless T is an alias declaration; in
> +                          which case our caller can be willing to
> +                          create a specialization of the alias
> +                          template represented by T.  If we hand her
> +                          T, she is going to clobber it.  So we'll
> +                          contruct a new T in this case, just like
> +                          for the case where T is not a class
> +                          member.  */
> +                       || !TYPE_DECL_ALIAS_P (t)))

I'm guessing that what this is trying to solve is the case of an 
instantiation of a member alias template?  In that case the problem is 
that the member is a template, and this code is assuming a non-template 
member.  Let's check for that instead of alias-declarations, as the 
existing code ought to work fine for regular alias members.

> +      else if (TYPE_DECL_ALIAS_P (decl))
> +       /* fall through.  */;

Why not set r here, as for the other cases?  It seems like this way you 
will lose cv-quals added to an alias.

Jason

  parent reply	other threads:[~2011-10-27 21:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-27 19:26 Dodji Seketeli
2011-10-27 22:16 ` Gabriel Dos Reis
2011-10-27 22:40 ` Jason Merrill [this message]
2011-11-06  2:19   ` Dodji Seketeli
2011-11-06 10:13     ` Jason Merrill
2011-11-07 15:57       ` Dodji Seketeli
2011-11-07 18:39         ` Jason Merrill
2011-11-08  3:40           ` [C++ PATCH] Fix context handling of alias declaration Dodji Seketeli
2011-11-08  5:13             ` Jason Merrill
2011-11-08 20:15         ` [C++ PATCH] PR c++/45114 - Support alias templates H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EA9CB03.5060708@redhat.com \
    --to=jason@redhat.com \
    --cc=bkoz@redhat.com \
    --cc=dodji@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).