Bug 8285 – Issue with slice returned from CTFE function

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-22T10:42:00Z
Last change time
2013-07-13T22:34:31Z
Assigned to
nobody
Creator
samukha
Depends on
7988

Comments

Comment #0 by samukha — 2012-06-22T10:42:33Z
import std.traits; string bar(T)() { alias ParameterStorageClassTuple!(T) scs; return ""; } string foo(string attrs) { return ""; } alias ref int function() Fn; enum baz2 = foo(bar!Fn()); \phobos\std\traits.d(99): Error: expression "NcZi"c[2u..4u] is not a valid template value argument This is the smallest case I have for now. Still trying to narrow it further.
Comment #1 by samukha — 2012-07-02T23:33:55Z
Test case 1: string foo() { string s = "ab"; return s[0 .. $]; } template T2(string s) { } template T1() { enum s = foo(); alias T2!(s) t2; } int bar() { alias T1!() t1; return 0; } int baz(int x) { return 0; } static assert(baz(bar()) == 0); void main() { } Error: expression "ab"[0u..2u] is not a valid template value argument Test case 2: string bar() { string s = "ab"; return s[0..$]; } template T1() { enum T1 = bar()[0..$]; // error } string baz() { return T1!(); } string foo(string s) { return s; } static assert(foo(baz()) == "ab"); void main() { } Error: variable __dollar cannot be read at compile time
Comment #2 by clugdbug — 2012-08-23T01:49:22Z
In the second example, adding the line + enum unused_enum = T1!(); string baz() { return T1!(); } makes the code work. It's because the const-folding code outside of CTFE is not as sophisticated as the code inside CTFE. Fixing bug 7988 would fix this.
Comment #3 by github-bugzilla — 2013-07-12T14:07:19Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f5c5d43e35a48d6cc63a2fe05c68f8b88ef5e21d Fix issue 8285 Issue with slice returned from CTFE function Test case only; fixed by using CTFE to do constfolding. https://github.com/D-Programming-Language/dmd/commit/a0ba3b2aa31d93709a1ed3e21f5a2deca6c761fc Merge pull request #2339 from donc/fourCTFEtestcases Test cases for bugs 1982, 7988, 8253, and 8285.