GNOME Bugzilla – Bug 644046
Initialization of non-const stack-allocated arrays fails
Last modified: 2014-10-25 12:07:35 UTC
The compiler generates incorrect code for the initialization of non-const stack-allocated arrays. i.e. int a[] = {1, 2, 3}; /* does not compile */ int a[3] = {1, 2, 3}; /* does not compile */ The code generated for both of the above fails to compile Sample code: /* array-test.vala */ int main (string[] args) { int a[] = {1, 2, 3}; /* does not compile */ return 0; } Compilation: $ valac array-test.vala array-test.vala:3.6-3.20: warning: local variable `a' declared but never used int a[] = {1, 2, 3}; /* does not compile */ ^^^^^^^^^^^^^^^ /home/graham/array-test.vala.c: In function ‘_vala_main’: /home/graham/array-test.vala.c:20: error: array size missing in ‘a’ /home/graham/array-test.vala.c:27: error: incompatible types when assigning to type ‘gint[1]’ from type ‘gint *’ /home/graham/array-test.vala.c:31: error: incompatible types when assigning to type ‘gint[1]’ from type ‘void *’ error: cc exited with status 256 Compilation failed: 1 error(s), 1 warning(s) Sample code: /* array-test.vala */ int main (string[] args) { int a[3] = {1, 2, 3}; /* does not compile */ return 0; } Compilation: $ valac array-test.vala array-test.vala:3.6-3.21: warning: local variable `a' declared but never used int a[3] = {1, 2, 3}; /* does not compile */ ^^^^^^^^^^^^^^^^ /home/graham/array-test.vala.c: In function ‘_vala_main’: /home/graham/array-test.vala.c:24: error: incompatible types when assigning to type ‘gint[3]’ from type ‘gint *’ error: cc exited with status 256 Compilation failed: 1 error(s), 1 warning(s)
*** Bug 644251 has been marked as a duplicate of this bug. ***
int a[3] = {1, 2, 3}; now compiles in master
Confirming
commit 0f0bca7e0519af13d9217fbca2c20ce67cd3baba Author: Florian Brosch <flo.brosch@gmail.com> Date: Thu Sep 18 05:09:03 2014 +0200 Infer array length of inline allocated arrays Fixes bug 644046. This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.