[cfe-commits] r58008 - /cfe/trunk/lib/Sema/SemaDecl.cpp
Douglas Gregor
dgregor at apple.com
Thu Oct 23 08:09:40 PDT 2008
On Oct 22, 2008, at 6:39 PM, Argiris Kirtzidis wrote:
> Douglas Gregor wrote:
>>
>> I don't think this is the right fix. If we find an invalid
>> redeclaration, we should just drop the redeclaration.
>
> Makes sense, but before I apply some fix I'd like to make sure, is
> this definitely the intended behavior ? Currently there's a test
> that assumes that name lookup finds the latest redeclaration, even
> if it's invalid.
> From test/Sema/predefined-function.c :
>
> int eli(float b); // expected-error {{previous declaration is here}}
> int b(int c) {return 1;}
>
> int foo();
> int foo()
> {
> int eli(int (int)); // expected-error {{conflicting types for
> 'eli'}}
> eli(b); #1
> return 0; }
>
> At #1, it's supposed to pick up the invalid redeclaration at the
> previous line.
I actually don't know the intent, but I can ask around. I could
imagine, for example, that one might actually want to do this: if we
get an invalid redeclaration, have PushOnScopeChains replace the
existing declaration with the new declaration, so that type-checking
can continue without having multiple, inconsistent declarations of the
same thing in scope.
But, that's a bit of work when we're not sure what the intent was, so
I'm going to withdraw my objection until such time as the thing I
describe below comes to pass, or we decide that we don't really need
overloading in C :)
>
>> There may still be uses for overloading when we're not in C++ mode
>> (e.g., for <tgmath.h>).
>
> Could you explain a bit more about this ?
<tgmath.h> is a C99 header that has several "type-generic" macros in
it, which are versions of common C standard library functions (acos,
atan, exp, etc.) whose type is the same as their input type, e.g.,
acos(float) is a float, acos(double) is a double, etc. Now, you can't
actually implement <tgmath.h> in C99, so one tends to use some kind of
builtins. However, one possible implementation is to have a little
incantation that allows C++ overloading in C, and to implement
tgmath.h using C++ overloading. I'd like to keep that possibility open.
- Doug
More information about the cfe-commits
mailing list