D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4639 - Built-in primitive types cannot be used as template alias parameters
Summary: Built-in primitive types cannot be used as template alias parameters
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-13 00:45 UTC by Deokjae Lee
Modified: 2015-06-09 05:11 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Deokjae Lee 2010-08-13 00:45:55 UTC
import std.stdio;

template T(alias X) {
}

void main() {
	writeln(typeid(typeof(T!int)));
}

dmd 2.048 on linux produces an error for the above code.

Error: template instance T!(int) does not match template declaration T(alias X)

Built-in primitive types cannot be used as template alias parameters. Structs and classes work well.
Comment 1 Don 2010-08-13 04:10:04 UTC
This is not a bug. From the spec:
"Alias parameters enable templates to be parameterized with any type of D symbol, including global names, local names, typedef names, module names, template names, and template instance names. Literals can also be used as arguments to alias parameters."

Built-in types are not on that list.
Comment 2 Deokjae Lee 2010-08-13 08:47:32 UTC
(In reply to comment #1)
> This is not a bug. From the spec:
> "Alias parameters enable templates to be parameterized with any type of D
> symbol, including global names, local names, typedef names, module names,
> template names, and template instance names. Literals can also be used as
> arguments to alias parameters."
> 
> Built-in types are not on that list.


Hmm.. I don't think so.

"parameterized with any type of D symbol, including ..."

Why are not built-in primitive types included in "any type of D symbol"?
Is there any particular reason that user defined type names (like struct names) are allowed but built-in type names are not allowed? I think such a limitation is not natural.
IMHO, If there is any good reason for the limitation, the phrase "any type of D symbol" should be removed from the spec. If there are no such reasons, then this should be considered as a bug.
Comment 3 Don 2010-08-13 12:02:20 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > This is not a bug. From the spec:
> > "Alias parameters enable templates to be parameterized with any type of D
> > symbol, including global names, local names, typedef names, module names,
> > template names, and template instance names. Literals can also be used as
> > arguments to alias parameters."
> > 
> > Built-in types are not on that list.
> 
> 
> Hmm.. I don't think so.
> 
> "parameterized with any type of D symbol, including ..."
> 
> Why are not built-in primitive types included in "any type of D symbol"?
> Is there any particular reason that user defined type names (like struct names)
> are allowed but built-in type names are not allowed? I think such a limitation
> is not natural.

I basically agree with you, but syntactically, they are quite different, and it's an intentional decision by Walter. See for example bug 1341.
Comment 4 Deokjae Lee 2010-08-13 21:06:48 UTC
Still I could not get the reason.
So, I posted a message to the mailing list to discuss this.
Comment 5 nfxjfg 2010-08-13 21:20:46 UTC
This spec is way to sh... I mean incomplete to interpret it literally. Also it is known that the spec is downright incorrect in many cases. I don't know why you would close this bug as invalid just because of the spec text. Also it's very inconsistent to exclude built-in types. About it being intentional by Walter: he actually fixed the mentioned bug 1341 and didn't close it as invalid. Finally, it's a D1 problem too.
Comment 6 Don 2010-08-13 22:33:12 UTC
>It's exactly the same issue as: typeof(int) is not legal.(In reply to comment #5)
> This spec is way to sh... I mean incomplete to interpret it literally. Also it
> is known that the spec is downright incorrect in many cases. I don't know why
> you would close this bug as invalid just because of the spec text.

NO. I requested Walter to make this change, and he rejected this before. It is definitely NOT a bug. A built-in type is not a D symbol.

> Also it's
> very inconsistent to exclude built-in types. About it being intentional by
> Walter: he actually fixed the mentioned bug 1341 and didn't close it as
> invalid. 

No, *I* changed the description of the bug after discussion with Walter. It was originally "typeof(int) should probably be legal".

> Finally, it's a D1 problem too.

No it isn't. It's an enhancement which would break existing code.
Comment 7 nfxjfg 2010-08-13 22:55:26 UTC
(In reply to comment #6)
> NO. I requested Walter to make this change, and he rejected this before. It is
> definitely NOT a bug. A built-in type is not a D symbol.

That's seriously stupid. Just another un-orthogonal feature that causes programmers headaches?

> No it isn't. It's an enhancement which would break existing code.

How?
Comment 8 Max Samukha 2010-08-14 01:45:44 UTC
I can't believe the limitation is deliberate. Please remove it if technically possible. Now the poor coder is forced to practice nonsense like:

template Foo(A...) if (A.length == 1) {}