Bug 4987 – C function pointer syntax needs to be deprecated

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-10-04T01:14:00Z
Last change time
2015-06-09T05:11:52Z
Keywords
patch
Assigned to
nobody
Creator
clugdbug
Blocks
2392

Comments

Comment #0 by clugdbug — 2010-10-04T01:14:13Z
This patch also gives a reasonable fix for bug 4962, "Improve error message for wrong constructor name?" It also gives nice error messages for missing return types in function declarations. Most importantly, it makes x(y) an invalid type, instead of being a declaration of a 'y', where &y is type 'x function()'. It's critical that syntax be removed. --- PATCH: parse.c, Parser::parseDeclarator() line 2497 ---- case TOKlparen: if (peekNext() == TOKmul || peekNext() == TOKlparen || peekNext() == TOKlbracket) { /* Parse things with parentheses around the identifier, like: * int (*ident[3])[] * although the D style would be: * int[]*[3] ident */ if (!global.params.useDeprecated) { error("C-style function pointer syntax is deprecated. Use 'function' to declare function pointers"); } nextToken(); ts = parseDeclarator(t, pident); check(TOKrparen); break; } ts = t; Token *peekt = &token; // Improve error messages for the common bug of a missing return type if (isParameters(&peekt)) { error("function declaration without return type. " "(Note that constructors are always named 'this')"); } else error("unexpected ( in declarator"); break;
Comment #1 by bugzilla — 2010-10-05T00:19:23Z
I changed it for D2 only, in order to avoid breaking existing D1 code. http://www.dsource.org/projects/dmd/changeset/703
Comment #2 by jlquinn — 2010-11-04T13:59:10Z
(In reply to comment #1) > I changed it for D2 only, in order to avoid breaking existing D1 code. > > http://www.dsource.org/projects/dmd/changeset/703 The language grammar (declaration.html) also needs to be updated.
Comment #3 by clugdbug — 2011-12-30T16:44:23Z
(In reply to comment #2) > (In reply to comment #1) > > I changed it for D2 only, in order to avoid breaking existing D1 code. > > > > http://www.dsource.org/projects/dmd/changeset/703 > > The language grammar (declaration.html) also needs to be updated. It's marked as deprecated in declaration.html. As long as it's deprecated but not removed, I think it should remain as part of the grammer.