Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
cb77c4c3
Commit
cb77c4c3
authored
Dec 28, 2012
by
liujisi@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generate a warning for duplicated enum values, when allow_alias option isn't
set.
parent
4770277e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
5 deletions
+18
-5
descriptor.cc
src/google/protobuf/descriptor.cc
+14
-4
descriptor_unittest.cc
src/google/protobuf/descriptor_unittest.cc
+3
-1
unittest.proto
src/google/protobuf/unittest.proto
+1
-0
No files found.
src/google/protobuf/descriptor.cc
View file @
cb77c4c3
...
...
@@ -4132,16 +4132,26 @@ void DescriptorBuilder::ValidateFieldOptions(FieldDescriptor* field,
void
DescriptorBuilder
::
ValidateEnumOptions
(
EnumDescriptor
*
enm
,
const
EnumDescriptorProto
&
proto
)
{
VALIDATE_OPTIONS_FROM_ARRAY
(
enm
,
value
,
EnumValue
);
if
(
!
enm
->
options
().
allow_alias
())
{
if
(
!
enm
->
options
().
has_allow_alias
()
||
!
enm
->
options
().
allow_alias
())
{
map
<
int
,
string
>
used_values
;
for
(
int
i
=
0
;
i
<
enm
->
value_count
();
++
i
)
{
const
EnumValueDescriptor
*
enum_value
=
enm
->
value
(
i
);
if
(
used_values
.
find
(
enum_value
->
number
())
!=
used_values
.
end
())
{
AddError
(
enm
->
full_name
(),
proto
,
DescriptorPool
::
ErrorCollector
::
NUMBER
,
string
error
=
"
\"
"
+
enum_value
->
full_name
()
+
"
\"
uses the same enum value as
\"
"
+
used_values
[
enum_value
->
number
()]
+
"
\"
"
);
used_values
[
enum_value
->
number
()]
+
"
\"
. If this is intended, set "
"'option allow_alias = true;' to the enum definition."
;
if
(
!
enm
->
options
().
allow_alias
())
{
// Generate error if duplicated enum values are explicitly disallowed.
AddError
(
enm
->
full_name
(),
proto
,
DescriptorPool
::
ErrorCollector
::
NUMBER
,
error
);
}
else
{
// Generate warning if duplicated values are found but the option
// isn't set.
GOOGLE_LOG
(
ERROR
)
<<
error
;
}
}
else
{
used_values
[
enum_value
->
number
()]
=
enum_value
->
full_name
();
}
...
...
src/google/protobuf/descriptor_unittest.cc
View file @
cb77c4c3
...
...
@@ -4001,7 +4001,9 @@ TEST_F(ValidationErrorTest, DisallowEnumAlias) {
" options { allow_alias: false }"
"}"
,
"foo.proto: Bar: NUMBER: "
"
\"
ENUM_B
\"
uses the same enum value as
\"
ENUM_A
\"\n
"
);
"
\"
ENUM_B
\"
uses the same enum value as
\"
ENUM_A
\"
. "
"If this is intended, set 'option allow_alias = true;' to the enum "
"definition.
\n
"
);
}
// ===================================================================
...
...
src/google/protobuf/unittest.proto
View file @
cb77c4c3
...
...
@@ -434,6 +434,7 @@ message TestNestedMessageHasBits {
// Test an enum that has multiple values with the same number.
enum
TestEnumWithDupValue
{
option
allow_alias
=
true
;
FOO1
=
1
;
BAR1
=
2
;
BAZ
=
3
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment