Bug 2415 – DMD allows void foo(int i, ); function definition
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-10-12T17:35:00Z
Last change time
2015-06-09T01:20:16Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
2korden
Comments
Comment #0 by 2korden — 2008-10-12T17:35:29Z
void foo(int i, ) //< note the comma
{
}
void main()
{
foo(1);
}
compiles and runs.
Comment #1 by bus_dbugzilla — 2008-10-12T23:49:34Z
I'm not sure but I think this might be intended in any place that accepts a comma separated list to make it easier to maintain long multi-line lists. For example, copy/pasting a bunch of entries from the start/middle of a list to the end and you don't have to worry about adding a comma after the former last element or removing the comma from the new last element. That's been my assumption, as I've actually found it useful for just that reason.
Comment #2 by dfj1esp02 — 2008-10-13T03:47:24Z
enum declaration has the same feature.
Comment #3 by samukha — 2008-10-13T04:48:18Z
But not array literals. I wish they also had this feature. It is useful for compile time generated code.
Comment #4 by bus_dbugzilla — 2008-10-13T14:45:17Z
From the newsgroup (Don):
>
> > I'm not sure but I think this might be intended in any place that accepts a
> > comma separated list to make it easier to maintain long multi-line lists. For
> > example, copy/pasting a bunch of entries from the start/middle of a list to the
> > end and you don't have to worry about adding a comma after the former last
> > element or removing the comma from the new last element. That's been my
> > assumption, as I've actually found it useful for just that reason.
>
> Is it documented anywhere?
For enums, and array and struct initializations: yes. For parameter and argument lists: not according to the grammars, however the inconsistency makes me wonder if (and hope) the "not allowed" ones were oversights.
The following appear to be the same in both D1 docs and D2 docs:
http://www.digitalmars.com/d/1.0/enum.html
EnumMembers:
EnumMember
EnumMember ,
EnumMember , EnumMembers
http://www.digitalmars.com/d/1.0/declaration.html
ArrayMemberInitializations:
ArrayMemberInitialization
ArrayMemberInitialization ,
ArrayMemberInitialization , ArrayMemberInitializations
StructMemberInitializers:
StructMemberInitializer
StructMemberInitializer ,
StructMemberInitializer , StructMemberInitializers
ParameterList:
Parameter
Parameter , ParameterList
Parameter ...
...
DeclaratorIdentifierList:
DeclaratorIdentifier
DeclaratorIdentifier , DeclaratorIdentifierList
http://www.digitalmars.com/d/1.0/template.html
TemplateParameterList
TemplateParameter
TemplateParameter , TemplateParameterList
TemplateArgumentList:
TemplateArgument
TemplateArgument , TemplateArgumentList
http://www.digitalmars.com/d/1.0/expression.html
NewExpression:
NewArguments Type [ AssignExpression ]
NewArguments Type ( ArgumentList )
NewArguments Type
NewArguments ClassArguments BaseClasslistopt { DeclDefs }
NewArguments:
new ( ArgumentList )
new ( )
new
ClassArguments:
class ( ArgumentList )
class ( )
class
ArrayLiteral:
[ ArgumentList ]
IndexExpression:
PostfixExpression [ ArgumentList ]
PostfixExpression:
PrimaryExpression
PostfixExpression . Identifier
PostfixExpression . NewExpression
PostfixExpression ++
PostfixExpression --
PostfixExpression ( )
PostfixExpression ( ArgumentList )
IndexExpression
SliceExpression
ArgumentList:
AssignExpression
AssignExpression , ArgumentList