]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't emit error-variable of CatchClause if not used
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 2 Mar 2020 20:05:38 +0000 (21:05 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 2 Mar 2020 20:05:56 +0000 (21:05 +0100)
Found by scan-build

codegen/valagerrormodule.vala

index b618f7b15e3e9b162f77641924e7860664fb8e95..79a96c47ffd8351d047d479ac36099b700cbaa86 100644 (file)
@@ -360,11 +360,14 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 
                ccode.open_block ();
 
-               if (clause.error_variable != null) {
+               if (clause.error_variable != null && clause.error_variable.used) {
                        visit_local_variable (clause.error_variable);
                        ccode.add_assignment (get_variable_cexpression (get_local_cname (clause.error_variable)), get_inner_error_cexpression ());
                        ccode.add_assignment (get_inner_error_cexpression (), new CCodeConstant ("NULL"));
                } else {
+                       if (clause.error_variable != null) {
+                               clause.error_variable.unreachable = true;
+                       }
                        // error object is not used within catch statement, clear it
                        cfile.add_include ("glib.h");
                        var cclear = new CCodeFunctionCall (new CCodeIdentifier ("g_clear_error"));