From: Jens Geyer Date: Sun, 3 Feb 2013 21:30:41 +0000 (+0100) Subject: THRIFT-1603 Thrift IDL allows for multiple exceptions, args or struct member names... X-Git-Tag: 0.9.1~191 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=3a67c2f834119b8a1148ab071443c8d12ce207a1;p=common%2Fthrift.git 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 ffe2af38..1d035423 100644 --- a/compiler/cpp/src/parse/t_struct.h +++ b/compiler/cpp/src/parse/t_struct.h @@ -108,8 +108,6 @@ class t_struct : public t_type { } bool append(t_field* elem) { - members_.push_back(elem); - typedef members_type::iterator iter_type; std::pair bounds = std::equal_range( members_in_id_order_.begin(), members_in_id_order_.end(), elem, t_field::key_compare() @@ -117,6 +115,11 @@ class t_struct : public t_type { 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 0a7f184e..2d90f21a 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -902,7 +902,7 @@ FieldList: 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); } }