Bug 2841 – char[] incorrectly accepted as a template value argument in D2

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-04-16T04:18:00Z
Last change time
2015-06-09T01:18:04Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2009-04-16T04:18:12Z
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; }
Comment #1 by jarrett.billingsley — 2009-04-16T10:05:57Z
Um, string literals are invariant(char)[]. The error message sure sucks, but it's not surprising that this doesn't work.
Comment #2 by clugdbug — 2009-04-16T10:48:48Z
(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.
Comment #3 by clugdbug — 2009-09-22T03:04:52Z
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)[].
Comment #4 by clugdbug — 2011-04-15T21:22:04Z
The example in comment 2 is fixed in this commit. https://github.com/donc/dmd/commit/fc67046cf1e66182d959309fb15ef9e2d4c266b9