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 744639 - Cannot compile code genereated by vala with clang -Werror=return-type
Cannot compile code genereated by vala with clang -Werror=return-type
Product: vala
Classification: Core
Component: Bindings: GLib
Other FreeBSD
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Reported: 2015-02-17 06:07 UTC by Ting-Wei Lan
Modified: 2015-02-24 15:52 UTC
See Also:
GNOME target: ---
GNOME version: ---

codegen: return default value in delegate wrappers (1.59 KB, patch)
2015-02-24 12:48 UTC, Luca Bruno
none Details | Review

Description Ting-Wei Lan 2015-02-17 06:07:26 UTC
This problem currently causes error when compiling anjuta. There is a simple vala code to reproduce the issue:

int main () {
    Thread.create<void>(() => {}, false);
    return 0;

Valac converts it to:

/* simplethread.c generated by valac, the Vala compiler
 * generated from simplethread.vala, do not modify */

#include <glib.h>
#include <glib-object.h>

gint _vala_main (void);
static void __lambda4_ (void);
static gpointer ___lambda4__gthread_func (gpointer self);

static void __lambda4_ (void) {

static gpointer ___lambda4__gthread_func (gpointer self) {
	__lambda4_ ();

gint _vala_main (void) {
	gint result = 0;
	GError * _inner_error_ = NULL;
	g_thread_create (___lambda4__gthread_func, NULL, FALSE, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	result = 0;
	return result;

int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
	return _vala_main ();

The problem is that ___lambda4__gthread_func doesn't have a return value, which causes clang -Werror=return-type to fail:

error: control reaches end of non-void function [-Werror,-Wreturn-type]
Comment 1 Maciej (Matthew) Piechotka 2015-02-17 06:21:52 UTC
As a general rule of thumb it's better not to compile Vala code with C compilers warnings enabled. While warnings tend to be very use for programmers they are often less so when autogenerating code as compiler should opt out for its simplicity and obvious correctness rather then simplicity and obviousness of generated code. For example it allows to unroll each function call into assignment to temporary variables regardless if the value is used later or not.

However the generated code may be incorrect per depending on g_thread_create implementation (or other function receiving the closure) so it should be fixed as Vala produce incorrect C code (i.e. one containing UB).
Comment 2 Luca Bruno 2015-02-17 09:04:57 UTC
Yes we should return a default value there. Thanks.
Comment 3 Luca Bruno 2015-02-24 12:48:13 UTC
Created attachment 297758 [details] [review]
codegen: return default value in delegate wrappers

Does the attached patch fix your problem?
Comment 4 Ting-Wei Lan 2015-02-24 15:49:49 UTC
Yes, it fixes the problem. Thanks.
Comment 5 Luca Bruno 2015-02-24 15:52:01 UTC
commit 9850121b6c3fe8c3a0fce3bc121c05483c5a1739
Author: Luca Bruno <>
Date:   Tue Feb 24 13:47:12 2015 +0100

    codegen: Return a default value in delegate wrappers
    Fixes bug 744639

This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.

After your distribution has provided you with the updated package - and if you have some time - please feel encouraged to verify the fix by changing the status of this bug report to VERIFIED. If the updated package does not fix the reported issue, please reopen this bug report.