-
Notifications
You must be signed in to change notification settings - Fork 15.9k
Description
What version of protobuf and what language are you using?
Version: vcpkg/v5.29.5
Language: C++
What operating system (Linux, Windows, ...) and version?
Windows 11 (PC that runs protobuf code generation), bare metal (i.e. no Operating System) for the environment on which the generated protobuf source code is to execute
What runtime / compiler are you using (e.g., python version or gcc version)
IAR C++ compiler with Libc++ library (Complete C/C++17 runtime library)
What did you do?
I'm attempting to compile a project in IAR that incorporates protobuf-generated files. I have linked the necessary includes from both protobuf and the IAR library, and have manually included approprate define statements for the IAR compiler throughout the protobuf include headers. However, as I resolved errors within IAR, a new error now returns upon attempting to compile my HostIDInfo.pb.cc file, which was built from a .proto file.
The compiler returns the error "Error[Pe028]: expression must have a constant value" on lines within the generated code that invoke the PROTOBUF_FIELD_OFFSET macro, defined in port_def.inc, within constexpr statements. The error notes "cannot use reinterpret_cast in constant-expression evaluation". Examples of the client code where this is invoked are shown below:
constexpr auto arena_bits = ::google::protobuf::internal::EncodePlacementArenaOffsets({
PROTOBUF_FIELD_OFFSET(Payload, impl.host_sw_version_) +
decltype(Payload::impl.host_sw_version_)::
InternalGetArenaOffset(
::google::protobuf::Message::internal_visibility()),
PROTOBUF_FIELD_OFFSET(Payload, impl.hostid_) +
decltype(Payload::impl.hostid_)::
InternalGetArenaOffset(
::google::protobuf::Message::internal_visibility()),
PROTOBUF_FIELD_OFFSET(Payload, impl.hosttime_) +
decltype(Payload::impl.hosttime_)::
InternalGetArenaOffset(
::google::protobuf::Message::internal_visibility()),
});
static constexpr ::int32_t kHasBitsOffset =
8 * PROTOBUF_FIELD_OFFSET(HostIdInfo, impl.has_bits);
Additionally, I have attempted to suppress this error using the diag_warning and diag_suppress command line options, and by similarly including #pragma statements at the end of port_def.inc, both of which were not successful.