Bug 1196 – regression: "cannot alias an expression"
Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-04-27T12:59:00Z
Last change time
2014-02-16T15:22:05Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
thomas-dloop
Comments
Comment #0 by thomas-dloop — 2007-04-27T12:59:31Z
This is an interresting case because small - and seemingly unrelated changes -
can cause the message to vanish:
# template removeSpace(char[] s, int x = 0) {
# static if (s[0] == ' '){
# alias removeSpace!(s[1..$], x+1) removeSpace;
# }else{
# alias s removeSpace;
# }
# }
#
# struct Tuple(A...) {
# alias A Tuple;
# }
# static assert("Hello you !" == removeSpace!(" Hello you !"));
compile/t/tuple_21_B.d(14): alias dstress.compile.t.tuple_21_B.removeSpace!("
Hello you !",6).removeSpace cannot alias an expression "Hello you !"
# static assert("Hello you !" == removeSpace!(" Hello you !").Tuple[0]);
succeeds
test cases:
http://dstress.kuehne.cn/nocompile/t/template_21_A.dhttp://dstress.kuehne.cn/nocompile/t/template_21_B.dhttp://dstress.kuehne.cn/run/template_12.d
Comment #1 by bugzilla — 2007-05-08T16:29:53Z
Both examples fail when I try it with the same error message. The error message is correct - an alias cannot be made of an expression (in this case, a string literal). A working example would be:
template removeSpace(char[] s, int x = 0)
{
static if (s[0] == ' '){
const char[] removeSpace = removeSpace!(s[1..$], x+1);
}else{
const char[] removeSpace = s;
}
}
struct Tuple(A...)
{
alias A Tuple;
}
static assert("Hello you !" == removeSpace!(" Hello you !"));