On Mon, Nov 7, 2011 at 7:54 AM, Dodji Seketeli <do...@redhat.com> wrote:
>> On 11/05/2011 07:36 PM, Dodji Seketeli wrote:
>> > +#define TYPE_DECL_NAMES_ALIAS_TEMPLATE_P(NODE)                         \
>>
>> This doesn't seem to be needed anymore.
>
> Removed, thanks.
>
>>
>> > +dump_alias_template_specialization (tree t, int flags)
>> > +{
>> > +  gcc_assert (alias_template_specialization_p (t));
>> > +
>> > +  if (CLASS_TYPE_P (t))
>> > +    dump_aggr_type (t, flags);
>> > +  else
>> > +    {
>> > +      tree name;
>> > +      name = TYPE_IDENTIFIER (t);
>> > +      pp_cxx_tree_identifier (cxx_pp, name);
>> > +      dump_template_parms (TYPE_TEMPLATE_INFO (t),
>> > +                          /*primary=*/false,
>> > +                          flags & ~TFF_TEMPLATE_HEADER);
>> > +    }
>>
>> Why do you treat class and non-class aliases differently?  In both
>> cases I think we want alias specializations to be printed as
>> scope::name<args>.  We don't want to print 'class' since such a
>> specialization cannot be used in an
>> elaborated-type-specifier.
>
> I didn't realize the elaborated-type-specifier case.  Fixed now.
>
>>
>> > +      if (alias_template_specialization_p (t))
>> > +       {
>> > +         dump_alias_template_specialization (t, flags);
>> > +         return;
>> > +       }
>> > +      else if ((flags & TFF_CHASE_TYPEDEF)
>> > +              || DECL_SELF_REFERENCE_P (decl)
>> > +              || (!flag_pretty_templates
>> > +                  && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO 
>> > (decl)))
>> >         t = strip_typedefs (t);
>>
>> The order of these two should be reversed.  We want TFF_CHASE_TYPEDEF
>> and -fno-pretty-templates to strip alias-templates as well as
>> non-template typedefs.
>
> Fixed.
>
>>
>> > -  /* If the next keyword is `namespace', we have a
>> > +  /* If the next keyword is `namespace', we have either a
>> >       namespace-alias-definition.  */
>>
>> This change seems unintended.
>
> Oops, fixed.  Thanks.
>
>>
>> > +      if (!(type_decl != NULL_TREE
>> > +           && TREE_CODE (type_decl) == TYPE_DECL
>> > +           && TYPE_DECL_ALIAS_P (type_decl)
>> > +           && DECL_TEMPLATE_INSTANTIATION (type_decl)))
>> > +       cp_parser_simulate_error (parser);
>>
>> I think the TYPE_DECL_ALIAS_P and DECL_TEMPLATE_INSTANTIATION checks
>> should be an assert instead; at this point any TYPE_DECL we get should
>> satisfy those.
>
> I did that initially and it revealed that the assertion can be
> violated by erroneous input code, e.g (in the test
> g++.dg/cpp0x/vt-34055.C):
>
>    template<typename...> struct B;
>    template<typename...T> struct B<T&> // { dg-error "parameter packs|T" }
>    {
>      void foo();
>    };
>
> Hence the recoverable error approach here.  So I am now just asserting
> the DECL_TEMPLATE_INSTANTIATION when the TYPE_DECL is for an alias
> declaration.  Is that better?
>
>>
>> > -         || (TYPE_P (t) && TYPE_DECL_ALIAS_P (TYPE_NAME (t)))
>> > +         || (TYPE_P (t)
>> > +             && TYPE_NAME (t)
>> > +             && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
>> > +             && TYPE_DECL_ALIAS_P (TYPE_NAME (t)))
>>
>> In C++ I think a non-null TYPE_NAME is always a TYPE_DECL.
>
> I wonder why I added that check there.  Removed now.
>
>>
>> >> Why not set r here, as for the other cases?
>> > Because I'd like to handle alias declarations even for cases handled
>> > by the other cases where, r is end up being NULL.
>>
>> Hmm.  With this code we end up substituting into a non-template alias
>> declaration at file scope.
>
> Ah, I see.
>
>> I think if you check alias_template_specialization_p before checking
>> for class/function scope that should handle the cases you need.
>
> alias_template_specialization_p wouldn't work as we'd miss the case
> where we precisely want to build an instantiation from an alias
> template.  So maybe the below is better?
>
> Thinking about that part of the code, I realized that the former patch
> didn't support (GNU extension) attributes so that part of the code
> wasn't tested enough.  I have thus added new tests that are a slight
> modification of the g++.dg/cpp0x/ext/tmplattr*.C tests to use the
> alias-template syntax and exercise that part of the code.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.
>
> From: Dodji Seketeli <do...@redhat.com>
> Date: Fri, 30 Sep 2011 12:52:52 +0200
> Subject: [PATCH] PR c++/45114 - Support alias templates
>
> gcc/cp/
>
>        * cp-tree.h (TYPE_DECL_ALIAS_P, TYPE_ALIAS_P)
>        (DECL_TYPE_TEMPLATE_P, DECL_ALIAS_TEMPLATE_P): New accessor
>        macros.
>        (TYPE_TEMPLATE_INFO): Get template info of an alias template
>        specializations from its TYPE_DECL.
>        (SET_TYPE_TEMPLATE_INFO): Set template info of alias template
>        specializations into its TYPE_DECL.
>        (DECL_CLASS_TEMPLATE_P): Re-write using the new
>        DECL_TYPE_TEMPLATE_P.
>        (enum cp_decl_spec): Add new ds_alias enumerator.
>        (alias_type_or_template_p, alias_template_specialization_p):
>        Declare new functions.
>        * parser.c (cp_parser_alias_declaration): New static function.
>        (cp_parser_check_decl_spec): Add "using" name for the `alias'
>        declspec.
>        (cp_parser_type_name): Update comment.  Support simple-template-id
>        representing alias template specializations in c++0x mode.
>        (cp_parser_qualifying_entity): Update comment.  Use
>        cp_parser_type_name.
>        (cp_parser_block_declaration): Handle alias-declaration in c++11.
>        Update comment.
>        (cp_parser_template_id): Handle specializations of alias
>        templates.
>        (cp_parser_member_declaration): Add alias-declaration production
>        to comment.  Support alias-declarations.
>        (cp_parser_template_declaration_after_export): Handle alias
>        templates in c++11.
>        * decl.c (make_typename_type, make_unbound_class_template): Accept
>        alias templates.
>        (grokdeclarator): Set TYPE_DECL_ALIAS_P on alias
>        declarations.
>        * decl2.c (grokfield): Move template creation after setting up the
>        TYPE_DECL of the alias, so that the TEMPLATE_DECL of the alias
>        template actually carries the right type-id of the alias
>        declaration.
>        * pt.c (alias_type_or_template_p)
>        (alias_template_specialization_p): Define new public functions.
>        (maybe_process_partial_specialization): Reject partial
>        specializations of alias templates.
>        (primary_template_instantiation_p): Consider alias template
>        instantiations.
>        (push_template_decl_real): Assert that TYPE_DECLs of alias
>        templates are different from those of class template.  Store
>        template info onto the TYPE_DECL of the alias template.
>        (convert_template_argument): Strip aliases from template
>        arguments.
>        (lookup_template_class_1): Handle the creation of the
>        specialization of an alias template.
>        (tsubst_decl): Create a substituted copy of the TYPE_DECL of an
>        member alias template.
>        (tsubst): Handle substituting into the type of an alias template.
>        Handle substituting UNBOUND_CLASS_TEMPLATE into
>        BOUND_TEMPLATE_TEMPLATE_PARM.
>        (do_type_instantiation): Better diagnostics when trying to
>        explicitely instantiate a non-class template.
>        * search.c (lookup_field_1, lookup_field_r): Support looking up
>        alias templates.
>        * semantics.c (finish_template_type): For instantiations of alias
>        templates, return the TYPE_DECL of the actual alias and not the
>        one of the aliased type.
>        * error.c (dump_alias_template_specialization): New static
>        function.
>        (dump_type): Handle printing of alias templates and their
>        specializations.  templates.
>        (dump_aggr_type): For specialization of alias templates, fetch
>        arguments from the right place.
>        (dump_decl): Print an alias-declaration like `using decl = type;'
>        (dump_template_decl):  Support printing of alias templates.
>

This caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51036

-- 
H.J.

Reply via email to