www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1100] New: Alias parameters don't accept primitive types.

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

           Summary: Alias parameters don't accept primitive types.
           Product: D
           Version: 1.010
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: reiner.pope gmail.com


template MyAlias(alias A)
{
    alias A MyAlias;
}

void main()
{
    alias MyAlias!(int) Myint; // This line fails: 
// template instance MyAlias!(int) does not match any template declaration
}

This disagrees with the spec
(http://www.digitalmars.com/d/template.html#aliasparameters) which says that
alias parameters can be type names -- I would certainly consider 'int' to be a
type name. Furthermore, it's unintuitive because a similar call like this works
fine:

struct Int
{
    int x;
}

void main()
{
    alias MyAlias!(Int) MyInt;
}


-- 
Apr 05 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1100


bugzilla digitalmars.com changed:

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




------- Comment #1 from bugzilla digitalmars.com  2007-04-06 02:06 -------
I changed "type names" to "typedef names" clarify it. The compiler works as
intended - use a template type parameter to pass an arbitrary type. "int" is a
keyword, not a symbol name.


-- 
Apr 06 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1100





------- Comment #2 from reiner.pope gmail.com  2007-04-06 02:51 -------
I would still argue that this is unintuitive behavior; to me an alias parameter
is anything that can be aliased. Allowing all types except primitive types in
alias parameters creates a seemingly arbitrary distinction between primitive
and user types -- don't we want to decrease these differences as much as
possible?

I can't think of any realistic use cases for primitive types as alias
parameters. However, I also can't for userland types.


PS. To be really pedantic, Int could be regarded as a symbol in the following:

alias int Int;
alias MyAlias!(Int) Int2; // MyAlias from before
// The above alias also doesn't work


-- 
Apr 06 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1100





------- Comment #3 from thomas-dloop kuehne.cn  2007-04-06 04:20 -------
Added to DStress as
http://dstress.kuehne.cn/compile/a/alias_42_A.d
http://dstress.kuehne.cn/compile/a/alias_42_B.d
http://dstress.kuehne.cn/nocompile/a/alias_42_C.d


-- 
Apr 06 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1100


spunit262 yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |spunit262 yahoo.com




------- Comment #4 from spunit262 yahoo.com  2007-11-09 21:23 -------
(In reply to comment #3)
 Added to DStress as
 http://dstress.kuehne.cn/compile/a/alias_42_A.d
 http://dstress.kuehne.cn/compile/a/alias_42_B.d
 http://dstress.kuehne.cn/nocompile/a/alias_42_C.d
 

Int isn't defined in C, so even if alias parameters did accept primitive types (which there isn't *any* reason for not to), it wouldn't compile. --
Nov 09 2007