THRIFT-897. compiler: Don't allow unqualified constant access to enum values
This patch makes it illegal to refer to enum values by just their names in the IDL. Now, you must also provide the enum type's name as well.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@996320 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index c7b1510..56b5c75 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -720,7 +720,13 @@
vector<t_enum_value*>::const_iterator c_iter;
bool found = false;
for (c_iter = enum_values.begin(); c_iter != enum_values.end(); ++c_iter) {
- if ((*c_iter)->get_name() == value->get_identifier()) {
+ size_t sub_index = value->get_identifier().find('.');
+ if (sub_index == string::npos) {
+ throw "error: identifier " + value->get_identifier() + " is unqualified!";
+ }
+ std::string name_portion = value->get_identifier().substr(sub_index+1);
+
+ if ((*c_iter)->get_name() == name_portion) {
found = true;
break;
}