[cfe-dev] [PATCH] Function redeclaration and PR2360
Eli Friedman
eli.friedman at gmail.com
Tue May 27 20:06:35 PDT 2008
On Tue, May 27, 2008 at 11:19 AM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
> Eli Friedman wrote:
>>
>> This means that references to a function before a
>> redeclaration refer to the old declaration, and references to a
>> function after a redeclaration refer to the new declaration.
>
> How about these cases:
>
> int a(int); // #1
> int a(); // #2
> int b(void) {a();} // should refer to #2 or is more accurate to refer to #1
> ?
a refers to #2; but note that per the rules about redeclaration, the
type of #2 is actually int(int). (See C99 6.2.7 p3 and p4.) clang
doesn't implement this bit correctly yet, though.
> And:
>
> int a(int x = 5); // #1
> int a(int x); // #2
> int b(void) {a();} // Shouldn't it refer to #1 ?
a again refers to #2; the only way that really makes sense here is to
have #2 point to the default argument from #1. Take the following
example:
int a(int x, int y = 3);
int a(int x = 5, int y);
Neither version of a has all the arguments; we have to propagate them
forward somehow. This is currently done in
Sema::MergeCXXFunctionDecl.
Note that there is currently a small bug here currently: declarations
can't determine whether they own a default argument, so we end up
leaking them.
-Eli
More information about the cfe-dev
mailing list