diff --git a/compiler2/ttcn3/Statement.cc b/compiler2/ttcn3/Statement.cc
index 5ce6b1ce0850bc4012ebda364381e83b18f32108..11614d38a3f204e7bfa32376de716213f848fdd0 100644
--- a/compiler2/ttcn3/Statement.cc
+++ b/compiler2/ttcn3/Statement.cc
@@ -9284,7 +9284,7 @@ error:
     char* constr_params_str = NULL;
     char* constr_init_list_str = NULL;
     char* set_values_str = NULL;
-    if (has_decoded_modifier()) {
+    if (matched_ti != NULL && has_decoded_modifier()) {
       // store a pointer to the matched template, the decoding results from
       // decmatch templates might be reused to optimize decoded value redirects
       expr->expr = mputprintf(expr->expr, "&(%s), ", matched_ti->get_last_gen_expr());
@@ -9335,8 +9335,9 @@ error:
       const char* subrefs_str = (subrefs_expr.expr != NULL) ? subrefs_expr.expr : "";
       if (v[i]->is_decoded()) {
         // set the silent parameter to 'true', so no errors are displayed
-        Template* matched_temp = matched_ti->get_Template()->get_refd_sub_template(
-          v[i]->get_subrefs(), false, NULL, true);
+        Template* matched_temp = matched_ti != NULL ?
+          matched_ti->get_Template()->get_refd_sub_template(v[i]->get_subrefs(),
+          false, NULL, true) : NULL;
         if (matched_temp != NULL) {
           matched_temp = matched_temp->get_template_refd_last();
         }
@@ -9460,7 +9461,7 @@ error:
               break;
             }
           }
-          if (unfoldable) {
+          if (unfoldable && matched_ti != NULL) {
             // the decmatch-check must be done at runtime
             use_decmatch_result = true;
             if (redir_coding_expr.preamble != NULL) {
diff --git a/compiler2/ttcn3/Statement.hh b/compiler2/ttcn3/Statement.hh
index e5135f9f94598fceac08972469e432c44f444b6f..ee5714c858e2bc33f10d0c062b55a3788eb6e172 100644
--- a/compiler2/ttcn3/Statement.hh
+++ b/compiler2/ttcn3/Statement.hh
@@ -1131,7 +1131,7 @@ namespace Ttcn {
       * structure. A new class is generated for every value redirect, which
       * handles the redirecting.
       * @param matched_ti the template instance used for matching the redirected
-      * value
+      * value (if NULL, then the template instance is an 'any value' template)
       * @param base_class_prefix the namespace and/or class prefix of the
       * base value redirect class of the appropriate type */
     void generate_code(expression_struct* expr, TemplateInstance* matched_ti,