GNOME Bugzilla – Bug 792942
async constructors that throw errors result in code, unbuildable with clang
Last modified: 2018-02-01 19:01:43 UTC
Things like https://gitlab.gnome.org/GNOME/gnome-boxes/blob/72cf086f819a72e49a2127ba36c2e819a3e58be0/src/installed-media.vala#L59 generate code that is unbuildable with clang, because empty returns in non-void functions are a hard error: /home/ernestas/jhbuild/checkout/gnome-boxes/src/installer-media.vala:64:3: error: non-void function 'boxes_installer_media_construct_for_path_finish' should return a value [-Wreturn-type] return; Reproducible with current stable (0.38.4) and current master (0.39.5.16-fbae7).
(In reply to Ernestas Kulik from comment #0) > /home/ernestas/jhbuild/checkout/gnome-boxes/src/installer-media.vala:64:3: > error: non-void function 'boxes_installer_media_construct_for_path_finish' > should return a value [-Wreturn-type] > return; > That’s from a different file, my bad, but those are sprinkled throughout the codebase.
I’m cooking up a patch. Got Boxes to build, but now working on adding a test.
Created attachment 367518 [details] [review] tests: add test for async ctors that throw
Created attachment 367519 [details] [review] codegen: fix returns in creation methods Currently, returns are generated with the return type of the creation method, but that fails if the creation method is also the constructor of a class/struct. This commit adds code to return valid values of parent types in those cases.
(In reply to Ernestas Kulik from comment #3) > Created attachment 367518 [details] [review] [review] > tests: add test for async ctors that throw This actually reveals more broken things, but I’m not yet sure how to go about those.
Created attachment 367530 [details] [review] codegen: Fix return-type for cancelled async creation methods of classes clang actually fails with -Werror=return-type
Hi, thanks for the patch, I have optimized it a bit and reduced it to only ObjectTypeSymbols, since as you noticed this looks like even more trouble with Structs. Struct "constructors" mostly have two types depending on if the struct can be handled as pointer/nullable type or simple-type. I prefer adding a test-case simultaneously.
Comment on attachment 367530 [details] [review] codegen: Fix return-type for cancelled async creation methods of classes Attachment 367530 [details] pushed as 6c50cfb - codegen: Fix return-type for cancelled async creation methods of classes