Skip to content

Avoid Windows ERROR macro collision in idl.h#9016

Open
steadytao wants to merge 2 commits intogoogle:masterfrom
steadytao:fix-8483-avoid-windows-error-macro-collision
Open

Avoid Windows ERROR macro collision in idl.h#9016
steadytao wants to merge 2 commits intogoogle:masterfrom
steadytao:fix-8483-avoid-windows-error-macro-collision

Conversation

@steadytao
Copy link
Copy Markdown

Summary

Avoid a Windows macro collision in flatbuffers/idl.h.

Problem

IDLOptions::ProtoIdGapAction currently defines an enumerator named ERROR.

On Windows, ERROR is commonly defined as a macro by system headers such as wingdi.h which causes flatbuffers/idl.h to fail to parse when both are included in the same translation unit.

Fix

  • rename IDLOptions::ProtoIdGapAction::ERROR to ERROR_
  • update the two internal references to that enumerator

Testing

  • rebuilt flatc
  • compiled a standalone translation unit with ERROR defined as a macro before including flatbuffers/idl.h
  • confirmed the header now parses cleanly in that configuration

Fixes #8483.

Rename IDLOptions::ProtoIdGapAction::ERROR to ERROR_ so flatbuffers/idl.h still parses when Windows headers define ERROR as a macro.

Update the two internal references in flatc.cpp and idl_gen_fbs.cpp.
@steadytao steadytao requested a review from dbaileychess as a code owner April 3, 2026 06:26
@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Apr 3, 2026
@jtdavis777
Copy link
Copy Markdown
Collaborator

while this does fix the reported issue (and may be sufficient to merge as is), when I started to look into this there are several other enumerations in the flatbuffers headers which also have this collision. I went to fix them but I believe there are some that are speciified by grpc which felt problematic to change.

@steadytao
Copy link
Copy Markdown
Author

I took a look and agree there are a few other ERROR enumerators with the same Windows macro-collision shape. I’m planning to expand this PR to cover the FlatBuffers-owned enums in public headers as well while avoiding gRPC-specified names since those feel riskier to rename.

Rename the remaining FlatBuffers-owned public-header ERROR enumerators to ERROR_ and update internal CodeGenerator::Status users accordingly.
@steadytao
Copy link
Copy Markdown
Author

Ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[c++] idl.h ERROR enum conflicts with windows define

2 participants