digitalmars.D.bugs - [Issue 11101] New: Invalid enum member overflow message
- d-bugmail puremagic.com (28/28) Sep 22 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11101
- d-bugmail puremagic.com (18/18) Sep 22 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11101
- d-bugmail puremagic.com (39/39) Sep 22 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11101
- d-bugmail puremagic.com (20/20) Sep 22 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11101
- d-bugmail puremagic.com (13/26) Sep 23 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11101
http://d.puremagic.com/issues/show_bug.cgi?id=11101 Summary: Invalid enum member overflow message Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: regression Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bugzilla digitalmars.com 10:43:17 PDT --- public enum GTokenType { NONE, } public enum GtkRcTokenType { INVALID = GTokenType.NONE, INCLUDE, } causes: test.d(9): Error: enum member test.GtkRcTokenType.INCLUDE initialization with (cast(GtkRcTokenType)cast(GTokenType)0 + 1) causes overflow -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 22 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11101 Maxim Fomin <maxim maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxim maxim-fomin.ru --- Citing spec: "If the EnumBaseType is not explicitly set, and the first EnumMember has an initializer, it is set to the type of that initializer. Otherwise, it defaults to type int." Since second enum is not explicitly based on int and has first enum initializer, that's why type of second enum is deduced to be GTokenType and overflow occures as the first enum has single member. So, according to current spec this is RESOLVED-INVALID. On the other hand, nothing stops from allowing such code for facilitation purposes by fixing spec. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 22 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11101 That would be a valid explanation only the following compiles successfully: public enum GTokenType { EOF = 0, LEFT_PAREN = '(', RIGHT_PAREN = ')', LEFT_CURLY = '{', RIGHT_CURLY = '}', LEFT_BRACE = '[', RIGHT_BRACE = ']', EQUAL_SIGN = '=', COMMA = ',', NONE = 110, ERROR, CHAR, BINARY, OCTAL, INT, HEX, FLOAT, STRING, SYMBOL, IDENTIFIER, IDENTIFIER_NULL, COMMENT_SINGLE, COMMENT_MULTI, LAST } public enum GtkRcTokenType { INVALID = GTokenType.LAST, INCLUDE, } If the value of NONE is larger than 110 it fails to compile. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 22 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11101 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID 17:20:11 PDT --- It should fail to compile with NONE larger than 110. The algorithm is if GTokenType.LAST==GTokenType.max, then attempting to calculate GTokenType.LAST+1 overflows it. To get what you are looking for, use: enum GtkRcTokenType { INVALID = GTokenType.LAST + 1, INCLUDE, } which will compile successfully. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 22 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11101It should fail to compile with NONE larger than 110. The algorithm is if GTokenType.LAST==GTokenType.max, then attempting to calculate GTokenType.LAST+1 overflows it.110 succeeds 111 fails in both cases GTokenType.LAST==GTokenType.max, both cases should either fail or succeed. Also note that when part of gtkD the enum overflows when NONE is 87, as far as i can tell this depends on the size of the GtkRcTokenType enum. This seems a bit inconsistent.To get what you are looking for, use: enum GtkRcTokenType { INVALID = GTokenType.LAST + 1, INCLUDE, } which will compile successfully.I'm casting GTokenType.LAST to int because the values of the enum need to correspond with there C counter part. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 23 2013