Thread overview
[Issue 2841] New: char[] template value arguments broken in D2
Apr 16, 2009
d-bugmail
Apr 16, 2009
d-bugmail
Apr 16, 2009
d-bugmail
[Issue 2841] char[] incorrectly accepted as a template value argument in D2
Sep 22, 2009
Don
Apr 16, 2011
Don
April 16, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2841

           Summary: char[] template value arguments broken in D2
           Product: D
           Version: 2.027
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: clugdbug@yahoo.com.au


int foo(char[] c)() { return 0; }

void main(){
        int a = foo!("abc")();
}
---
fog.d(6): Error: template fog.foo(char[] c) does not match any function
template
 declaration
fog.d(6): Error: template fog.foo(char[] c) cannot deduce template function
from
 argument types !("abc")()
fog.d(6): Error: template instance errors instantiating template

This all works in D1.042. Fails in D2.028.
The code below is similar. Also for class and union.
--
struct C(char[] c){ }

void main(){
   C!("abc") a;
}


-- 

April 16, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2841





------- Comment #1 from jarrett.billingsley@gmail.com  2009-04-16 10:05 -------
Um,

string literals are invariant(char)[].

The error message sure sucks, but it's not surprising that this doesn't work.


-- 

April 16, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2841


clugdbug@yahoo.com.au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|regression                  |major
           Keywords|rejects-valid               |spec




------- Comment #2 from clugdbug@yahoo.com.au  2009-04-16 10:48 -------
(In reply to comment #1)
> Um,
> 
> string literals are invariant(char)[].

Indeed.

> The error message sure sucks, but it's not surprising that this doesn't work.

But there is no way that a mutable char [] could be passed as a template value
parameter. And it's not a type. So what is
template(char[] X) ?

int foo(char[] c)() { return 0; }

void main(){
   char [] z;
   int a = foo!(z)(); // ok
}

I can't see anything in the spec to indicate what this means. From the .mangleof, it seems to be accepting it as an alias parameter.

OK, I'll change this to a spec error.


-- 

September 22, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2841


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|spec                        |accepts-invalid
            Summary|char[] template value       |char[] incorrectly accepted
                   |arguments broken in D2      |as a template value
                   |                            |argument in D2
           Severity|major                       |normal


--- Comment #3 from Don <clugdbug@yahoo.com.au> 2009-09-22 03:04:52 PDT ---
Here's a test case which illustrates the problem better.

int foo(char[])() { return 0; }

bug.d(1): identifier expected for template value parameter

---
So it clearly thinks it is a template value parameter, but it's impossible in D2 to have a char[] compile-time value! It must be immutable(char)[].

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2841


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

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


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2011-04-15 21:22:04 PDT ---
The example in comment 2 is fixed in this commit. https://github.com/donc/dmd/commit/fc67046cf1e66182d959309fb15ef9e2d4c266b9

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