Skip to content

Fix issues with repeated enums with unique, defined_only, in and not_in for cc and go#1360

Open
fishcakez wants to merge 1 commit intobufbuild:mainfrom
fishcakez:repeated-enum-cc-go
Open

Fix issues with repeated enums with unique, defined_only, in and not_in for cc and go#1360
fishcakez wants to merge 1 commit intobufbuild:mainfrom
fishcakez:repeated-enum-cc-go

Conversation

@fishcakez
Copy link
Contributor

When trying to use repeated enums with unique, defined_only, in or not_in encountered issues with cc and go implementations.

For go, the generated code for repeated enum when using defined_only could be incorrect when importing enums from multiple packages with name collisions. The imports are correct (e.g. _go, _go1) but the defined check would always use the first case (e.g. _go). The test added will fail to compile without the fix:

undefined: _go.DeepEnum_name

For cc, then generated code for repeated enum when using unique has issue with const_cast from int -> enum. Therefore for repeated unique enum use set of int to avoid cast/reference wrapper. The tested added will fail to compile without the fix:

error: invalid 'const_cast' from type 'const int*' to type 'tests::harness::cases::AnEnum*'
  664 |                                 auto p = _RepeatedUniqueEnum_Val_Unique.emplace(const_cast<AnEnum&>(item));

For cc, the generated code for repeated enum when using in or not_in has incorrect namespace where :: separator is not used, and instead _ is. Therefore use correct package name helper for cc. The test added will fail to compile without the fix:

error: 'nested' was not declared in this scope; did you mean 'tests::harness::cases::other_package::nested'?
 1249 |         const std::set<nested::DeepEnum> _RepeatedExternalEnumMultiLevel_Foo_InLookup = {

Signed-off-by: James Fish <jfish@pinterest.com>
@CLAassistant
Copy link

CLAassistant commented Feb 4, 2026

CLA assistant check
All committers have signed the CLA.

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.

2 participants