www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - "enum" in function declaration

reply Timon Gehr <timon.gehr gmx.ch> writes:
Currently, DMD accepts declarations of the form:

enum int foo(){writeln("foo!\n");return 123;}

which seems to be exactly equivalent to

int foo(){writeln("foo!\n");return 123;}

However, enum foo(){writeln("foo!\n");return 123;} is rejected.

Given the fact that enum is also used for declaring manifest constants, this
does seem odd. No semantic implications are added to a function declaration
when extended by the enum storage class.

I see two possibilities:

1. Disallow "enum" functions.
2. Allow, and make the "enum" function compile-time only.


Timon
May 29 2011
parent bearophile <bearophileHUGS lycos.com> writes:
Timon Gehr:

 Given the fact that enum is also used for declaring manifest constants, this
 does seem odd. No semantic implications are added to a function declaration
 when extended by the enum storage class.

Don tacit regarding the word "tidy", see also: http://d.puremagic.com/issues/show_bug.cgi?id=3934 Bye, bearophile
May 29 2011