On Thu, Oct 16, 2008 at 01:18:24PM +0100, Dave Korn wrote: > Lasse Kärkkäinen wrote on 15 October 2008 20:12: > > > The problem here is that the C++ standard requires line 8 to be > > interpreted as a declaration of a function named str, returning string > > and taking two arguments of type isbi (the first one is named cin and > > the second one is anonymous). The extra parenthesis around variable > > names are ignored. > > > > However, since it is not conventional to use parenthesis around variable > > names in function declarations, this problem could be analyzed by GCC, > > issuing a proper warning. > > Can anyone point me at an explanation of why this (parentheses around > variable names in prototypes) is even allowed? I assume that the proximal > cause is "Because the standard says so", but does it actually buy us anything > in terms of what can be expressed that otherwise couldn't?
I think it's an accidental consequence of the grammar, but it is certainly ugly. My guess is that it has something to do with the ugly declarators you have to write for pointers to functions and the like. > Standards compliance and all that, but maybe in std=gnu++ mode we could make > it an error, or perhaps deprecated? I think it would make sense to ask the standards committee to declare it an error, and we should certainly warn. By the way, my recent experience with this C++ language flaw was something like the following (though I'll change the example to use standard classes): using std::pair; using std::string; void func(const char* first, const char* second) { // the following declares a function named foo, not a pair named foo pair<string,string> foo(string(first), string(second)); ... }