www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12020] New: Instantiating a template struct with equivalent const and enum arguments creates two types.

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

           Summary: Instantiating a template struct with equivalent const
                    and enum arguments creates two types.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mason.b.mcgill gmail.com


--- Comment #0 from Mason McGill <mason.b.mcgill gmail.com> 2014-01-28 14:48:33
PST ---
This took me quite a few hours to figure out, and I can't think of any reason
this would be desired behavior:

//===========================================================================//

import std.stdio;

struct S(int n) {}

void main()
{
    enum e = 1;
    const c = 1;
    writeln(is(S!e == S!e)); // true.
    writeln(is(S!c == S!c)); // true. all good so far...
    writeln(is(S!e == S!c)); // false. that seems buggy...
    writeln(is(S!e == S!(cast(int) c))); // true. now that just can't be right.
}

//===========================================================================//

Unless I'm missing something, the expected behavior is to create a single type.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 28 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12020


Stanislav Blinov <stanislav.blinov gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |stanislav.blinov gmail.com


--- Comment #1 from Stanislav Blinov <stanislav.blinov gmail.com> 2014-01-28
15:26:11 PST ---
typeof(e) == int - an underlying type of an enum.
typeof(c) == const(int).

Hence two distinct types.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 28 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12020



--- Comment #2 from Mason McGill <mason.b.mcgill gmail.com> 2014-01-28 15:34:42
PST ---
(In reply to comment #1)
 typeof(e) == int - an underlying type of an enum.
 typeof(c) == const(int).
 
 Hence two distinct types.

Right--so that should yield two distinct template instances if you were parameterizing by type, like this: struct S1(T) {} but my example involved parameterizing by value, like this: struct S1(int n) {} Since the value of `cast(int)(e)` and `cast(int)(c)` are the same, shouldn't the two types be the same? Also, writeln(S1!e()); // prints the same output as writeln(S1!c()); // which is pretty confusing if they're not the same type. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 28 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12020



--- Comment #3 from Stanislav Blinov <stanislav.blinov gmail.com> 2014-01-28
15:45:37 PST ---
Oh, hmm... Didn't think it through. Yeah, that seems odd indeed.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 28 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12020


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k.hara.pg gmail.com,
                   |                            |yebblies gmail.com


--- Comment #4 from yebblies <yebblies gmail.com> 2014-01-29 17:31:26 EST ---
This looks like the same thing as issue 3467 - which is strange because that
was fixed.  Kenji?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 28 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12020


Kenji Hara <k.hara.pg gmail.com> changed:

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


--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2014-01-28 22:53:05 PST ---
(In reply to comment #4)
 This looks like the same thing as issue 3467 - which is strange because that
 was fixed.  Kenji?

No. This is a dup of issue 7469. *** This issue has been marked as a duplicate of issue 7469 *** -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 28 2014