[cfe-dev] PATCH: C++ Function Overloading (v2)
Argiris Kirtzidis
akyrtzi at gmail.com
Tue Oct 21 11:23:15 PDT 2008
Doug Gregor wrote:
> On Tue, Oct 21, 2008 at 6:35 AM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
>
>> Doug Gregor wrote:
>>
>>> Templates will need to store sets of overloaded functions.
>>>
>>>
>> Even now, with no trace of a template implementation in clang, the use of
>> OverloadedFunctionDecl is questionable:
>>
>> -First, consider this example:
>>
>> void f(char); #1
>>
>> template<class T> void g(T t)
>> {
>> f(t); #2 //dependent
>> }
>>
>> void f(int); #3
>>
>> void h()
>> {
>> g(2); #4 //should cause a call of f(int)
>> }
>>
>>
>> At #2 'f' does not have any overloads and no OverloadedFunctionDecl exists,
>> how should this be represented ?
>>
>
> It's just a FunctionDecl, because #1 is the only f. That's what we're doing now.
>
Hmm.. this is taken verbatim from C++ 03 14.6p9:
void f(char);
template<class T> void g(T t)
{
f(1); // f(char)
f(T(1)); //dependent #1
f(t); //dependent #2
dd++; //not dependent // error: declaration for dd not found
}
void f(int);
double dd;
void h()
{
g(2); //will cause one call of f(char) followed
// by two calls of f(int)
g(’a’); //will cause three calls of f(char)
}
Note that it says "g(2)" will cause one call of f(char) followed by two
calls of f(int). By regarding the 'f', inside the template, just a
FunctionDecl (the "f(char)" one), won't this result to 3 calls of f(char) ?
By 14.6.2p1, the 'f' inside the template (at #1 and #2) is a dependent
name and "Such names are unbound and are looked up at the point of the
template instantiation (14.6.4.1) in both the context of the template
definition and the context of the point of instantiation". Doesn't that
mean that 'f' is not a simple FunctionDecl (since it's actually unbound) ?
> Iterators can be arbitrarily complex, so it's not that the iterator
> abstraction *couldn't* handle this. The thing I like best about the
> iterator abstraction is that it doesn't require us to allocate any
> memory like returning a set of decls does, and doesn't expose any one
> particular data structure. That said, the iterator itself will need to
> get some more configurability---follow using directives or don't
> follow using directives?, to name one---that might cost us too much in
> iteration overhead.
>
Yes, my concern is about the overhead, we could get away with it with
not much of an impact though, not too sure.
-Argiris
More information about the cfe-dev
mailing list