Bug 1456 – Cannot use a constant with alias template parameters

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-08-30T10:29:00Z
Last change time
2014-02-16T15:21:37Z
Keywords
rejects-valid
Assigned to
nobody
Creator
samukha

Comments

Comment #0 by samukha — 2007-08-30T10:29:03Z
<code> const int i = 20; template Foo(alias bar) { } alias Foo!(i) foo; </code> Error: template instance Foo!(20) does not match any template declaration Please note that the compiler handles the situation correctly if the initializer for i is left out: <code> const int i; template Foo(alias bar) { alias bar Foo; } alias Foo!(i) foo; pragma(msg, foo.stringof); // now foo is aliased to i as expected </code> D 2.0 has the same problem.
Comment #1 by clugdbug — 2007-09-13T07:22:23Z
I don't think this is a bug. In the second case, the value of i is not known until runtime. It's really just a variable. But the first case is identical to alias Foo!(20) foo; which shouldn't compile.
Comment #2 by samukha — 2007-09-13T09:26:19Z
But in the first example the global name i and not 20 is aliased. It is according to the specs. If it's not a bug, I would expect the following not to work either: const int i = 20; alias i j; // Should fail with an error like "cannot alias 20 to j"?
Comment #3 by samukha — 2009-10-21T01:09:41Z
Not a blocker but still a bug, IMO. dmd 2.035 handles it right.
Comment #4 by clugdbug — 2012-11-21T00:42:37Z
This is not a bug. The reason it works in D2 is that D2 allows expressions as template alias parameters.