[cfe-dev] PATCH: C++ Function Overloading (v2)

Doug Gregor doug.gregor at gmail.com
Tue Oct 21 14:01:09 PDT 2008

On Tue, Oct 21, 2008 at 1:37 PM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
> Doug Gregor wrote:
>> Yeah, the example is correct. This was noted in DR 197:
>>  http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#197
> Oh, incorrect examples in the standard, the fun never ends... ;)


> Then OverloadedFunctionDecl has a different issue, consider this:
> void f(char); #1
> void f(int); #2
> template<class T> void g(T t)
> {
> f(t); #3 //dependent
> }
> void f(float); #4
> void h()
> {
> g(2.3); #5
> f(2.3);  #6
> }
> At #3 there's an OverloadedFunctionDecl for the template to reference. But
> what about #4 ?
> If it gets added to the same OverloadedFunctionDecl then #5 will incorrectly
> pick it up, while we do want #6 to pick it up.
> Will there be two OverloadedFunctionDecls, one for the template and another
> for normal lookup in #6 ? That seems to defeat its purpose.

I figured we would have two OverloadedFunctionDecls. I don't think it
defeats the purpose, because the AST is storing the set of overloaded
functions that it saw.

> How about the 'f' in the template at #3 gets represented as a
> DependentNameExpr which contains:
> -either a list of FunctionDecls found with normal lookup in the template
> context
> -or a DeclContext* and IdentifierInfo* and in order to get the FunctionDecls
> visible in template context we do not consider declarations that appeared
> after the DependentNameExpr (using SourceLocation to check)

Both of these are reasonable representations for DependentNameExpr or
OverloadedFunctionDecl, because in many ways they are expressing the
same notion (although the latter also has its place, at least
temporarily, in non-template code).

I'm guessing that we probably won't need DependentNameExpr, because
dependent names don't really exist on their own in the AST. Rather,
they come about as a property of the arguments used with that name,
e.g., "f" in "f(blah)" is a dependent name if blah is a type-dependent
expression, "+" in "a + b" is a dependent name is "a" or "b" is a
type-dependent expression, etc. "f" or "+" could just as well be
represented by a (possibly empty!) OverloadedFunctionDecl that is
either the callee of a CallExpr or the initial overloaded operator set
of some hypothetical, overloaded version of BinaryOperator.

  - Doug

More information about the cfe-dev mailing list