[vala/staging] codegen: Don't emit error-variable of CatchClause if not used



commit b090ccc0b75f759bbe3c211420e7c76bccc9afe8
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Mar 2 21:05:38 2020 +0100

    codegen: Don't emit error-variable of CatchClause if not used
    
    Found by scan-build

 codegen/valagerrormodule.vala | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index b618f7b15..79a96c47f 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -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"));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]