c++/9836: [3.4 regression] Error with typdefs in partial specializations of classes

bangerth@dealii.org bangerth@dealii.org
Mon Feb 24 21:15:00 GMT 2003

Synopsis: [3.4 regression] Error with typdefs in partial specializations of classes

Responsible-Changed-From-To: unassigned->mmitchel
Responsible-Changed-By: bangerth
Responsible-Changed-When: Mon Feb 24 21:15:04 2003
    Mark, this problem appears with your change 1.662->1.663 of
    pt.c, which comes from this patchset:
    2003-02-23  Mark Mitchell  <mark@codesourcery.com>
            PR c++/5333
            * cp-tree.h (CLASSTYPE_PRIMARY_TEMPLATE): New macro.
            * parser.c (cp_parser_diagnose_invalid_type_name): Use it.
            * pt.c (instantiate_class_template): Don't try to instantiate
            dependent types.
            (resolve_typename_type): Use CLASSTYPE_PRIMARY_TEMPLATE.
    If I back out the pt.c change, the program compiles cleanly
    again, so it looks like that's where the problem lies.
    For reference: the patch to pt.c is this one:
    diff -u -r1.662 -r1.663
    --- pt.c        20 Feb 2003 17:51:43 -0000      1.662
    +++ pt.c        24 Feb 2003 07:43:22 -0000      1.663
    @@ -5151,7 +5151,9 @@
       if (type == error_mark_node)
         return error_mark_node;
    -  if (TYPE_BEING_DEFINED (type) || COMPLETE_TYPE_P (type))
    +  if (TYPE_BEING_DEFINED (type)
    +      || COMPLETE_TYPE_P (type)
    +      || dependent_type_p (type))
         return type;
       /* Figure out which template is being instantiated.  */
    @@ -11526,6 +11528,10 @@
          to look inside it.  */
       if (only_current_p && !currently_open_class (scope))
         return error_mark_node;
    +  /* If SCOPE is a partial instantiation, it will not have a valid
    +     TYPE_FIELDS list, so use the original template.  */
    +  if (CLASSTYPE_USE_TEMPLATE (scope))
    +    scope = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (scope);
       /* Enter the SCOPE so that name lookup will be resolved as if we
          were in the class definition.  In particular, SCOPE will no
          longer be considered a dependent type.  */
    A testcase is this:
    template <bool, int> struct X {};
    template <bool C>    struct X<C,1> {
        typedef double* type;
        type foo () const;
    template <bool C>
    typename X<C,1>::type
    X<C,1>::foo () const {}
    and it fails with
    g/x> ../../gcc/bin/gcc/cc1plus -quiet y.cc
    y.cc:10: error: prototype for `typename X<C, 1>::type X<C, 1>::foo() const'
       does not match any in class `X<C, 1>'
    y.cc:5: error: candidate is: double* X<C, 1>::foo() const
    y.cc:10: error: template definition of non-template `typename X<C, 1>::type
       X<C, 1>::foo() const'
State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Mon Feb 24 21:15:04 2003


More information about the Gcc-bugs mailing list