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 684262 - wrong code generated for inline array of struct with generic type argument
wrong code generated for inline array of struct with generic type argument
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Arrays
unspecified
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks: 664084
 
 
Reported: 2012-09-18 01:24 UTC by Daiki Ueno
Modified: 2018-05-22 14:29 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Daiki Ueno 2012-09-18 01:24:32 UTC
Given the following code:

struct Entry<K,V> {
	K key;
	V value;
}

int main (string[] args) {
	const Entry<int,string>[] map = {
		{ 0, "foo" },
		{ 1, "bar" }
	};
	stdout.printf ("%d %s\n", map[0].key, map[1].value);
	return 0;
}

valac -C generates:

typedef struct _Entry Entry;

struct _Entry {
	gpointer key;
	gpointer value;
};

static const Entry map[] = {{0, "foo"}, {1, "bar"}}; // (*)

I heard that some compiler does not accept (*)[1].  It seems that a proper cast from integer to pointer (such as "(gintptr)" or "GINT_TO_POINTER") is required.

1. https://github.com/ueno/libskk/issues/20
Comment 1 Michael 'Mickey' Lauer 2018-02-23 12:48:30 UTC
Thanks for your report. I agree that this might not be safe on all architectures and should be fixed. Apple clang 9.0 reports:

% valac bar.vala                                                                                                                       /tmp/bar.c:40:14: warning: assigning to 'gpointer' (aka 'void *') from 'gconstpointer' (aka 'const void *') discards qualifiers
      [-Wincompatible-pointer-types-discards-qualifiers]
        (*dest).key = _tmp0_;
                    ^ ~~~~~~
/tmp/bar.c:42:16: warning: assigning to 'gpointer' (aka 'void *') from 'gconstpointer' (aka 'const void *') discards qualifiers
      [-Wincompatible-pointer-types-discards-qualifiers]
        (*dest).value = _tmp1_;
                      ^ ~~~~~~
/tmp/bar.c:88:44: warning: incompatible integer to pointer conversion initializing 'gpointer' (aka 'void *') with an expression of type 'int' [-Wint-conversion]
        static const Entry map[2] = {{0, "foo"}, {1, "bar"}};
                                                  ^
3 warnings generated.
Comment 2 GNOME Infrastructure Team 2018-05-22 14:29:41 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/320.