Topic: Type-id Ambiguity
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: 1995/05/22 Raw View
shepherd@debussy.sbi.com (Marc Shepherd) writes:
> template<class T> void f();
> template<int I> void f();
> void g() {
> f<int()>(); // ``int()'' is a type-id; call the first f()
> }
>
>If I read the grammar correctly, the type-id ``int()'' corresponds
>(in English) to "function taking no arguments, returning int".
Yes, that looks right to me.
>If so, the template instantiation would (it seems) be ill-formed on
>semantic grounds.
>
>Am I correct?
I don't think so.
Ill-formed on which semantic grounds? It looks fine to me.
--
Fergus Henderson | I'll forgive even GNU emacs as
fjh@cs.mu.oz.au | long as gcc is available ;-)
http://www.cs.mu.oz.au/~fjh | - Linus Torvalds
Author: shepherd@debussy.sbi.com (Marc Shepherd)
Date: 1995/05/19 Raw View
The template clause of the draft WP includes the
following statement and accompanying example:
In a template-argument, an ambiguity between a type-id
and an expression is resolved to a type-id. [Example:
template<class T> void f();
template<int I> void f();
void g()
{
f<int()>(); // ``int()'' is a type-id; call the first f()
}
--end example]
If I read the grammar correctly, the type-id ``int()'' corresponds
(in English) to "function taking no arguments, returning int". If
so, the template instantiation would (it seems) be ill-formed on
semantic grounds.
Am I correct?
---
Marc Shepherd
Salomon Brothers Inc
shepherd@schubert.sbi.com The opinions I express are no one's but mine!
Author: jhs@edg.com (John H. Spicer)
Date: 1995/05/19 Raw View
In article <3pi79i$ihm@offas_dike.sbil.co.uk> shepherd@debussy.sbi.com writes:
>The template clause of the draft WP includes the
>following statement and accompanying example:
>
> In a template-argument, an ambiguity between a type-id
> and an expression is resolved to a type-id. [Example:
>
> template<class T> void f();
> template<int I> void f();
>
> void g()
> {
> f<int()>(); // ``int()'' is a type-id; call the first f()
> }
>
> --end example]
>
>If I read the grammar correctly, the type-id ``int()'' corresponds
>(in English) to "function taking no arguments, returning int". If
>so, the template instantiation would (it seems) be ill-formed on
>semantic grounds.
>
>Am I correct?
>
You are right about what the type of T would be. Such a type could,
however, be used within f() in valid ways (e.g., creating a pointer of
that type).
John Spicer
Edison Design Group