This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/795
- To: Nathan Sidwell <nathan at codesourcery dot com>
- Subject: Re: c++/795
- From: Martin Sebor <sebor at roguewave dot com>
- Date: Mon, 27 Nov 2000 15:04:10 -0700
- CC: nathan at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org
- Organization: Rogue Wave Software, Inc.
- References: <20001124141600.12709.qmail@sourceware.cygnus.com> <3A1EB56D.31CB7D0@roguewave.com> <3A2223CA.AC285747@codesourcery.com>
Nathan Sidwell wrote:
>
> Martin Sebor wrote:
> >
> > I don't think it is ill-formed. From
> > http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#30:
> thanks, but I don't see how that is relevant. It's talking about something
> in a non-template scope. Here we are in the scope of a templated member
> function. Besides, disallowing template here would change the validity of
> the example between paras 4 and 5 in 14.2, which is currently isomorphic
> to this test case.
>
> Do you agree?
I'm not sure I understand the distinction you're making between the scopes. In
any case, however, the intent is that the simplified testcase below compile. The
current snapshot (actually, gcc-20001113) gives an error.
The distinction (which isn't made in 14.2 but which the note in CWG issue 30
clarifies) is between what's on the left of ., ->, and :: and what's on the
right. If the lhs of the operator depends on a template parameter, the keyword
template is required. If the lhs doesn't depend on a template parameter, the
keyword is optional.
In the testcase, though, even if the error were appropriate (which I'm convinced
it's not), there would be a problem with the compiler accepting the first
construct. So no matter how you look at it, there's a problem.
Regards
Martin
struct A
{
template<typename T>
T foo () const;
};
struct B
{
template<typename T>
void bar () const {
A *a = 0;
A().foo<T>(); // okay
a[0].foo<T>(); // error? NOT!
}
} ;
int main ()
{
B ().bar<int> ();
}
Here's another more comprehensive testcase that should IMO compile as well (it
does with EDG eccp 2.44).
template <class T>
struct S
{
template <class U>
void foo () { }
};
template <class T>
void bar ()
{
S<int> si;
S<T> st;
S<int> *psi = 0;
S<T> *pst = 0;
si.foo<int>();
si.foo<T>();
st.template foo<int>();
st.template foo<T>();
psi->foo<int>();
psi->foo<T>();
pst->template foo<int>();
pst->template foo<T>();
psi[0].foo<int>();
psi[0].foo<T>();
pst[0].template foo<int>();
pst[0].template foo<T>();
S<int>::foo<int>();
S<int>::foo<T>();
S<T>::template foo<int>();
S<T>::template foo<T>();
}
int main ()
{
bar<int>();
}
>
> nathan
> --
> Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
> 'But that's a lie.' - 'Yes it is. What's your point?'
> nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org