Topic: definition of "member" and point of implicit instantiation (14.7.1)


Author: "Jason Shirk" <jasonsh__n_o_s_p_a_m__@microsoft.com>
Date: Mon, 3 Dec 2001 00:03:32 GMT
Raw View
Is the following a legal program?

//--- begin
template <class T>
struct Outer {
    struct Inner1 {
        struct Inner2 : T { };
        void func() {
            typename T::Other t;
        }
    };
};

Outer<int>::Inner1 inner1;
//--- end

14.7.1 says that when a class template specialization is referenced, it's
members declarations are implicitly instantiated.  The members'
definitions are not implicitly instantiated unless referenced.

Above, Outer<int>::Inner1 is referenced, so the definition should be
implicitly instantiated.  Outer<int>::Inner1 is not a class template, and
therefore I would expect Outer<int>::Inner1::Inner2 and
Outer<int>::Inner1::func to be instaniated when Outer<int>::Inner1 is
instantiated.  However, both of these members cannot be instantiated with
T=int, so a compiler should issue an error.

Both Comeau 4.2.45.2 and GCC 2.95 compile this without any error, Borland
gives an error saying 'int' is not a valid base class.  This would imply
Borland is instantiating Inner2 when Inner1 is instantiated, but Comeau
and GCC do not.

While I think Comeau and GCC implement the intent of the standard, I don't
see any wording that makes this explicit.  I thought maybe the resolution
of defect report 45 (nested classes access is transitive to all members in
the nested member) would help here, but it doesn't.

So, my question is:

Is a member of a nested member also a member of a class template?  If so,
is there wording in the standard or a defect report that explains this?
If not, am I missing something, or are Comeau and GCC non-conforming in
this regard?

Jason Shirk


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]