From: David Reiss Date: Mon, 13 Sep 2010 17:32:14 +0000 (+0000) Subject: Fix enum value lookups in C++ X-Git-Tag: 0.5.0~40 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=bdd6261b3336cbb7f3df2829e0c001f6591bb224;p=common%2Fthrift.git Fix enum value lookups in C++ The recent enum change was causing enums to break if used as constant values by the C++ generator. The problem was that we were searching for the fully-qualified constant name (enum_name.VALUE_NAME) in the enum values. This didn't affect Java because it just uses symbolic names in the generated code. Fix it by grabbing the base name before doing the search. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@996610 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/parse/t_const_value.h b/compiler/cpp/src/parse/t_const_value.h index b66372b9..43c28b10 100644 --- a/compiler/cpp/src/parse/t_const_value.h +++ b/compiler/cpp/src/parse/t_const_value.h @@ -71,10 +71,15 @@ class t_const_value { if (enum_ == NULL) { throw "have identifier \"" + get_identifier() + "\", but unset enum on line!"; } - t_enum_value* val = enum_->get_constant_by_name(get_identifier()); + std::string identifier = get_identifier(); + std::string::size_type dot = identifier.rfind('.'); + if (dot != std::string::npos) { + identifier = identifier.substr(dot+1); + } + t_enum_value* val = enum_->get_constant_by_name(identifier); if (val == NULL) { throw - "Unable to find enum value \"" + get_identifier() + + "Unable to find enum value \"" + identifier + "\" in enum \"" + enum_->get_name() + "\""; } return val->get_value();