THRIFT-5540 Can't use a typedef for a container type containing enums in a constant
Patch: Jens Geyer
diff --git a/compiler/cpp/src/thrift/main.cc b/compiler/cpp/src/thrift/main.cc
index 50bdcea..c5aa65f 100644
--- a/compiler/cpp/src/thrift/main.cc
+++ b/compiler/cpp/src/thrift/main.cc
@@ -1000,6 +1000,9 @@
       dump_docstrings(program);
     }
 
+    // make sure all symbolic constants are properly resolved
+    program->scope()->resolve_all_consts();
+
     vector<string>::const_iterator iter;
     for (iter = generator_strings.begin(); iter != generator_strings.end(); ++iter) {
       t_generator* generator = t_generator_registry::get_generator(program, *iter);
diff --git a/compiler/cpp/src/thrift/parse/t_scope.h b/compiler/cpp/src/thrift/parse/t_scope.h
index a12c4df..17a360f 100644
--- a/compiler/cpp/src/thrift/parse/t_scope.h
+++ b/compiler/cpp/src/thrift/parse/t_scope.h
@@ -25,6 +25,7 @@
 #include <sstream>
 
 #include "thrift/parse/t_type.h"
+#include "thrift/parse/t_typedef.h"
 #include "thrift/parse/t_service.h"
 #include "thrift/parse/t_const.h"
 #include "thrift/parse/t_const_value.h"
@@ -96,7 +97,20 @@
     }
   }
 
+  void resolve_all_consts() {
+    std::map<std::string, t_const*>::iterator iter;
+    for (iter = constants_.begin(); iter != constants_.end(); ++iter) {
+      t_const_value* cval = iter->second->get_value();
+      t_type* ttype = iter->second->get_type();
+      resolve_const_value(cval, ttype);
+    }
+  }
+
   void resolve_const_value(t_const_value* const_val, t_type* ttype) {
+    while (ttype->is_typedef()) {
+      ttype = ((t_typedef*)ttype)->get_type();
+    }
+
     if (ttype->is_map()) {
       const std::map<t_const_value*, t_const_value*, t_const_value::value_compare>& map = const_val->get_map();
       std::map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter;