www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8888] New: char enums inside functions

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8888

           Summary: char enums inside functions
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



If I try to define the char enum inside the function I receive error messages
from the compiler and the linker (DMD 2.061alpha):

-------------------

void main() {
    enum Code : char { A='A', B='B', C='C' }
    auto arr = [Code.A, Code.B];
}


OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj(test) 
 Error 42: Symbol Undefined _Dmain4Code6__initZ

-------------------

void main() {
    enum Code : char { A='A', B='B', C='C' }
    auto arr = [Code.A, Code.B];
}

test.d(2): Error: no identifier for declarator Code
test.d(2): Error: semicolon expected, not ':'
test.d(2): Error: found ':' instead of statement
test.d(4): Error: unrecognized declaration

-------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 24 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8888


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx



Confirmed on Linux 64-bit, git HEAD. Moving the enum outside main() works
correctly.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8888




This bug seems to happen only if you assign specific values to the enum. This
works:

void main() {
    enum Code : char { A, B, C }
    auto arr = [Code.A, Code.B];
}

But this doesn't:

void main() {
    enum Code { A=1, B=2, C=2 }
    auto arr = [Code.A, Code.B];
}

So the bug isn't specific to char enums, it's just the presence of initializers
that trigger it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8888




This code works correctly on GDC (gdc-4.7 git branch, which I believe is 2.059
based), so this seems to be a backend bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8888




Another data point: changing 'auto' to 'char[]' makes it work. Specifying
'Code[]' makes it fail.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8888


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com
         OS/Version|Windows                     |All



02:05:59 PST ---
Related bug:

unittest
{
    enum En8143 : int { A = 10, B = 20, C = 30, D = 20 }
    enum En8143[][] m3 = to!(En8143[][])([[10, 30], [30, 10]]);
    static assert(m3 == [[En8143.A, En8143.C], [En8143.C, En8143.A]]);
}

This breaks both the win32 and posix linkers.

The following fixes the win32 linker, but it doesn't fix the posix linker:

version(unittest)
{
    enum En8143 : int { A = 10, B = 20, C = 30, D = 20 }
    enum En8143[][] m3 = to!(En8143[][])([[10, 30], [30, 10]]);
    static assert(m3 == [[En8143.A, En8143.C], [En8143.C, En8143.A]]);
}

unittest
{
    // ...
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8888


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



07:37:02 PST ---
The pull for Issue 6057 fixes this.

*** This issue has been marked as a duplicate of issue 6057 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 10 2013