Skip to content

MSVC C++ compliance: Using __builtin_offsetof #20229

Open
@Radnyx

Description

@Radnyx

Hi folks,

This is in regard to the definition of PROTOBUF_FIELD_OFFSET:

#define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \
static_cast< ::uint32_t>(reinterpret_cast<const char*>( \
&reinterpret_cast<const TYPE*>(16)->FIELD) - \
reinterpret_cast<const char*>(16))

The Visual C++ team found that this macro is supposed to cause a compiler error. It uses reinterpret_cast in constexpr statements, which isn't allowed by the standard. We intend to emit an error for this macro in future versions of MSVC.

Fortunately, MSVC supports __builtin_offsetof, so we ask that you use that instead. Let me know if you have any questions.

Thank you.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions