Skip to content

fix(cpp): suppress self-warning on deprecated enum value imports (#28012)#28185

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_937631530
Jun 26, 2026
Merged

fix(cpp): suppress self-warning on deprecated enum value imports (#28012)#28185
copybara-service[bot] merged 1 commit into
mainfrom
test_937631530

Conversation

@copybara-service

Copy link
Copy Markdown

fix(cpp): suppress self-warning on deprecated enum value imports (#28012)

Fixes #18205.

protoc generates a class-scoped alias for each nested enum value (for example static constexpr Status OK = Result_Status_OK;). For a value marked [deprecated = true], the alias is itself [[deprecated]] and initializes from the deprecated enumerator, so protoc's own generated header trips -Wdeprecated-declarations. That breaks downstream builds compiled with -Werror, even though the user does not control the generated code. This wraps the alias in the existing PROTOBUF_IGNORE_DEPRECATION_START/PROTOBUF_IGNORE_DEPRECATION_STOP macros, as suggested by a maintainer on the issue. Non-deprecated values are unchanged.

Test: added two cases to generator_unittest.cc (one asserting the wrap is emitted for a deprecated value, one asserting no macro is emitted otherwise).

./build/tests --gtest_filter='CppGeneratorTest.*'

Result: all CppGeneratorTest cases pass (including the two new ones).

Closes #28012

COPYBARA_INTEGRATE_REVIEW=#28012 from yashanil98:fix/issue-18205-enum-symbol-import-deprecation 2cad7bc
FUTURE_COPYBARA_INTEGRATE_REVIEW=#28012 from yashanil98:fix/issue-18205-enum-symbol-import-deprecation 2cad7bc

)

Fixes #18205.

protoc generates a class-scoped alias for each nested enum value (for example `static constexpr Status OK = Result_Status_OK;`). For a value marked `[deprecated = true]`, the alias is itself `[[deprecated]]` and initializes from the deprecated enumerator, so protoc's own generated header trips `-Wdeprecated-declarations`. That breaks downstream builds compiled with `-Werror`, even though the user does not control the generated code. This wraps the alias in the existing `PROTOBUF_IGNORE_DEPRECATION_START`/`PROTOBUF_IGNORE_DEPRECATION_STOP` macros, as suggested by a maintainer on the issue. Non-deprecated values are unchanged.

Test: added two cases to `generator_unittest.cc` (one asserting the wrap is emitted for a deprecated value, one asserting no macro is emitted otherwise).

  ./build/tests --gtest_filter='CppGeneratorTest.*'

Result: all CppGeneratorTest cases pass (including the two new ones).

Closes #28012

COPYBARA_INTEGRATE_REVIEW=#28012 from yashanil98:fix/issue-18205-enum-symbol-import-deprecation 2cad7bc
PiperOrigin-RevId: 938705268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecating 'enum' field inside a 'message' causes compiler warning 'deprecated-declarations' in generated C++ header

1 participant