GNOME Bugzilla – Bug 778224
Codegen creating void returns throwing error in method returning a SimpleType
Last modified: 2017-02-10 08:21:53 UTC
If a method returns a SimpleType struct, and has a block in which an exception is thrown, then the return statement in the generated code when the error is thrown is void, rather than some default value such as NULL. Eg: > [SimpleType] > struct Foo { ... } > > Foo foo() { > if (blah) { > throw new Example.EXAMPLE(""); > // void return generated here > } > ... > } Generates for foo: > Foo foo (GError** error) { > Foo result = {0}; > ... > if (_tmp0_) { > GError* _tmp1_ = NULL; > _tmp1_ = g_error_new_literal (EXAMPLE, EXAMPLE_EXAMPLE, ""); > _inner_error_ = _tmp1_; > g_propagate_error (error, _inner_error_); > return; > } > ... > return result; > } Note the void return at the end of the if block, I'd expect it to be "return result" or "return NULL". This happens for both 0.34.4 and git master.
NB, while gcc generates a warning for the void return, clang I think errors out on it by default, see Bug 778046.
Created attachment 345009 [details] Minimal-ish test case A compilable example that triggers the bug.
Created attachment 345013 [details] [review] Don't return void for non-nullable SimpleType structs by default Attached patch fixes the problem for me. Both Vala.GErrorModule::return_with_exception and ::uncaught_error_statement were calling ::return_default_value to output the return value, so I updated that to check for a non-null SimpleType struct and if found, 0-initialise a new blank var and return that.
Please recheck your patch, make sure your patch compiles and passes make check. It is weird that gcc doesn't fail with -Werror=return-type in the first place.
Created attachment 345034 [details] [review] codegen: Don't return void for non-nullable simple-type structs
(In reply to Rico Tzschichholz from comment #4) > Please recheck your patch, make sure your patch compiles and passes make > check. > > It is weird that gcc doesn't fail with -Werror=return-type in the first > place. Ah, sorry, will do. Updating it seems to be a bit non-trivial, will get to it when I have a moment to find out what happened to ::create_local.
I guess you noticed I already pushed an updated patch for testing?
Attachment 345034 [details] pushed as c73d19c - codegen: Don't return void for non-nullable simple-type structs