Bug 1599 – compile time evaluation with immutable problem
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-10-19T21:29:00Z
Last change time
2015-06-09T01:14:19Z
Keywords
rejects-valid
Assigned to
nobody
Creator
braddr
Comments
Comment #0 by braddr — 2007-10-19T21:29:12Z
This compiles:
template foo(A...) { invariant char[] foo = A[0]; }
static assert(foo!("a") == "a");
This doesnt:
template foo(A...) { invariant(char)[] foo = A[0]; }
static assert(foo!("a") == "a");
The error: static assert (foo == "a") is not evaluatable at compile time
the difference is the ()'s around char, it's subtle. :)
Comment #1 by clugdbug — 2011-04-14T15:30:31Z
The compiler doesn't give the normal 'invariant is deprecated' error message for the first case. I think it's not running semantic() on it.
Comment #2 by clugdbug — 2012-11-12T07:14:59Z
template foo(A...) { immutable(char)[] foo = A[0]; }
static assert(foo!("a") == "a");
----
vug.d(2): Error: variable foo cannot be read at compile time
vug.d(2): while evaluating: static assert(foo == "a")
This is because foo is a mutable run-time array of immutable(char). Not a bug.