Skip to content

protoc: c++ windows #defines IN, OUT, and OPTIONAL to empty strings #7076

@scotthart

Description

@scotthart

What version of protobuf and what language are you using?
Version: 3.8.0
Language: C++

What operating system (Linux, Windows, ...) and version?
Windows

What runtime / compiler are you using (e.g., python version or gcc version)
msvc

What did you do?
including field_behavior.pb.h generated from https://github.com/googleapis/googleapis/blob/c9dce519127b97e866ca133a01157f4ce27dcceb/google/api/field_behavior.proto#L57 in other files results in a malformed enum definition for google::api::FieldBehavior

What did you expect to see
field_behavior.pb.h was emitted containing:

enum FieldBehavior { FIELD_BEHAVIOR_UNSPECIFIED = 0, OPTIONAL = 1, REQUIRED = 2, OUTPUT_ONLY = 3, INPUT_ONLY = 4, IMMUTABLE = 5, FieldBehavior_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::google::protobuf::int32>::min(), FieldBehavior_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::google::protobuf::int32>::max() }; 

What did you see instead?
When included after <windows.h> the resulting .i file contains:

enum FieldBehavior : int { FIELD_BEHAVIOR_UNSPECIFIED = 0, = 1, REQUIRED = 2, OUTPUT_ONLY = 3, INPUT_ONLY = 4, IMMUTABLE = 5, FieldBehavior_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::google::protobuf::int32>::min(), FieldBehavior_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::google::protobuf::int32>::max() }; 

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
Code example: https://godbolt.org/z/W_zBzC
The offending header is minwindef.h https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.10240.0/shared/minwindef.h#L87
Notice it also #defines IN and OUT to empty strings as well.

Anything else we should know about your project / environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions