Thread overview
[Issue 1456] New: Cannot use a constant with alias template parameters
Aug 30, 2007
d-bugmail
Sep 13, 2007
d-bugmail
Sep 13, 2007
d-bugmail
Oct 21, 2009
Max Samukha
Nov 21, 2012
Don
August 30, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1456

           Summary: Cannot use a constant with alias template parameters
           Product: D
           Version: 1.020
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: samukha@voliacable.com


<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.


-- 

September 13, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1456





------- Comment #1 from clugdbug@yahoo.com.au  2007-09-13 07:22 -------
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.


-- 

September 13, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1456





------- Comment #2 from samukha@voliacable.com  2007-09-13 09:26 -------
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"?


-- 

October 21, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1456


Max Samukha <samukha@voliacable.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|blocker                     |normal


--- Comment #3 from Max Samukha <samukha@voliacable.com> 2009-10-21 01:09:41 PDT ---
Not a blocker but still a bug, IMO. dmd 2.035 handles it right.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=1456


Don <clugdbug@yahoo.com.au> changed:

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


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2012-11-21 00:42:37 PST ---
This is not a bug. The reason it works in D2 is that D2 allows expressions as template alias parameters.

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