THRIFT-1603 Thrift IDL allows for multiple exceptions, args or struct member names to be the same
Patch: Kamil Sałaś
diff --git a/compiler/cpp/src/parse/t_struct.h b/compiler/cpp/src/parse/t_struct.h
index ffe2af3..1d03542 100644
--- a/compiler/cpp/src/parse/t_struct.h
+++ b/compiler/cpp/src/parse/t_struct.h
@@ -108,8 +108,6 @@
   }
 
   bool append(t_field* elem) {
-    members_.push_back(elem);
-
     typedef members_type::iterator iter_type;
     std::pair<iter_type, iter_type> bounds = std::equal_range(
             members_in_id_order_.begin(), members_in_id_order_.end(), elem, t_field::key_compare()
@@ -117,6 +115,11 @@
     if (bounds.first != bounds.second) {
       return false;
     }
+    // returns false when there is a conflict of field names
+    if (get_field_by_name(elem->get_name()) != NULL) {
+      return false; 
+    }
+    members_.push_back(elem);
     members_in_id_order_.insert(bounds.second, elem);
     validate_union_member( elem);
     return true;
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index 0a7f184..2d90f21 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -902,7 +902,7 @@
       pdebug("FieldList -> FieldList , Field");
       $$ = $1;
       if (!($$->append($2))) {
-        yyerror("Field identifier %d for \"%s\" has already been used", $2->get_key(), $2->get_name().c_str());
+        yyerror("\"%d: %s\" - field identifier/name has already been used", $2->get_key(), $2->get_name().c_str());
         exit(1);
       }
     }