# HG changeset patch
# User mjsousa
# Date 1392224528 0
# Node ID 7365c3e5c9ae6b55371c43ff3057269492223407
# Parent  300c27c0875390bfec4be56a43e0d0c8d25274ed
Fix bug: when checking compatibility between GLOBAL and EXTERNAL variables, must only enforce GLOBAL CONSTANT => EXTERNAL CONSTANT.
Reverse CONSTANT implication is not enforced, and neither is RETAIN compatibility.

diff -r 300c27c08753 -r 7365c3e5c9ae stage3/declaration_check.cc
--- a/stage3/declaration_check.cc	Tue Feb 11 10:55:27 2014 +0000
+++ b/stage3/declaration_check.cc	Wed Feb 12 17:02:08 2014 +0000
@@ -112,8 +112,14 @@
         continue;
       }
       
-      if (search_var_instance_glo_decl->get_option(var_name) != search_var_instance_ext_decl.get_option(var_name))
-        STAGE3_ERROR(0, glo_decl, glo_decl, "Declaration error.  The external variable options do not match with thos of the global variable.");
+      /* Check whether variable's constness (CONSTANT) is compatible.
+       *        VAR_GLOBAL is contant     => VAR_EXTERNAL must also be CONSTANT
+       *        VAR_GLOBAL is not contant => VAR_EXTERNAL may be CONSTANT, or not!
+       */
+      search_var_instance_decl_c::opt_t ext_opt = search_var_instance_ext_decl. get_option(var_name);
+      search_var_instance_decl_c::opt_t glo_opt = search_var_instance_glo_decl->get_option(var_name);
+      if ((glo_opt == search_var_instance_decl_c::constant_opt) && (ext_opt != search_var_instance_decl_c::constant_opt))
+        STAGE3_ERROR(0, glo_decl, glo_decl, "Declaration error. The external variable must be declared as constant, as it maps to a constant global variable.");
 
       /* TODO: Check redefinition data type.
        *       We need a new class (like search_base_type class) to get type id by variable declaration.