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