clang allows illegal redeclaration of function?
| Bugzilla Link | 1890 |
| Resolution | FIXED |
| Resolved on | Mar 12, 2010 00:59 |
| Version | unspecified |
| OS | Linux |
| CC | @akyrtzi |
Extended Description
int b(int c) {return 1;}
int f(float b) { return 0; }
void a(void){ int f(int (int)); f(b); }
I think this code should give a compile error. Both gcc and the comeau c compiler give an error on this code, but clang does not; instead, clang emits code with an rather dangerous function cast.
Not sure if this is the right component.
This was fixed recently, at least for C.
Ok, it's about time this ancient bug gets revived :)
void f(void) { void ss(void); } float ss; // error: 'ss' redeclared as different kind of symbol
gcc and comeau emitting error for the above seems to indicate that Steve is right and the function decl should be added to the top level scope.
Also, comeau emits this kind of error for C++ too, while g++ doesn't; should clang follow the comeau example ?
o.k. I'm not surprised the behavior is undefined. I agree a diagnostic is in order. I'm going to leave this open for now...I have more important fish to fry. Will get back to it...my partial fix yesterday pushes the ball forward a bit (and handles a more common case, I believe).
Adding the function to the top-level scope doesn't sound completely right... the first declaration of ss isn't actually visible at the point where the error should occur. It's just that it's not legal to have multiple conflicting definitions for the same function... According to the standard, "If, within a translation unit, the same identifier appears with both internal and external linkage, the behavior is undefined.", and "All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined." So the behavior of the program in comment 2 appears to be undefined by the standard... although a diagnostic definitely seems like the most reasonable way to deal with it.
Well if you wanted both "bugs" fixed, you should have included the second case originally (just kidding:-).
It looks like we should always add the function decl to the top level scope. Before we make this change, we should consult the spec. If you feel motivated to work on this, let me know (I think it would be a good "first commit" project). If not, I'm happy finish it. Your call.
Not really fixed; try the following:
int r (int) { int ss(void); } int ss(int);
You are correct...this is an error. Fixed in r45789.