[Issue 15153] CTFE failes to access second dimension of static arrays

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Oct 4 13:15:19 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15153

--- Comment #3 from ag0aep6g at gmail.com ---
(In reply to tobias.marstaller from comment #2)
> Okey, i understand that. I changed my test snippet to this but the compiler
> still gives an error for the array declaration:
> 
> ----
> module std.test;
> 
> static int[][] staticTable = [[1, 2], [3, 4]];
> static int[][] staticallyDerivedTable = deriveTable(staticTable);
> 
> static int[][] deriveTable(int[][] table)
> {
> 	int[table.length][table[0].length] newTable;
> 	
> 	// ... do something
> 	
> 	return newTable;
> }
> ----

Here `table` is a dynamic array. That makes `table.length` a dynamic value.
Again, it may actually be a constant, but the compiler doesn't try that. It's
really the same scenario as before.

CTFE follows the same rules as run time evaluation (plus some additional
restrictions). When some code doesn't compile for run time, then it's not
supposed to work in CTFE.

I'd like to suggest you make a thread on the learn group
(<http://forum.dlang.org/group/learn>) if the rules of CTFE are maybe still a
bit foggy for you. Or make a thread on the general group
(<http://forum.dlang.org/group/general>) if you feel that the rules as they are
could be improved. And if you feel that the documentation is not explaining the
details of CTFE properly, feel free to file an issue on that, of course.

I'm not closing again to avoid back and forth status changes. I'm confident
that everything works as designed, though. If you agree that the issue is
invalid, please let me know, or just close it yourself.

--


More information about the Digitalmars-d-bugs mailing list