After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 644046 - Initialization of non-const stack-allocated arrays fails
Initialization of non-const stack-allocated arrays fails
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.11.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 644251 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-03-06 22:17 UTC by gawhelan
Modified: 2014-10-25 12:07 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description gawhelan 2011-03-06 22:17:46 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)
Comment 1 Luca Bruno 2011-03-10 16:59:39 UTC
*** Bug 644251 has been marked as a duplicate of this bug. ***
Comment 2 Luca Bruno 2011-06-27 12:04:12 UTC
int a[3] = {1, 2, 3}; now compiles in master
Comment 3 geert jordaens 2011-07-25 15:13:33 UTC
Confirming
Comment 4 Luca Bruno 2014-10-25 12:07:35 UTC
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.