Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC C++ compliance: Using __builtin_offsetof #20229

Open
Radnyx opened this issue Feb 4, 2025 · 5 comments
Open

MSVC C++ compliance: Using __builtin_offsetof #20229

Radnyx opened this issue Feb 4, 2025 · 5 comments

Comments

@Radnyx
Copy link

Radnyx commented Feb 4, 2025

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.

@Radnyx Radnyx added the untriaged auto added to all issues by default when created. label Feb 4, 2025
@JasonLunn JasonLunn added c++ windows and removed untriaged auto added to all issues by default when created. labels Feb 5, 2025
@JasonLunn
Copy link
Contributor

@Radnyx - can you confirm whether the change that landed in 92f8c5b addresses this issue for you?

@Radnyx
Copy link
Author

Radnyx commented Feb 5, 2025

Hi @JasonLunn, yes this is what we had in mind!

One thing to address: Since MSVC is introducing a compiler error, we're worried that if customers upgrade MSVC, they might run into friction and need to regenerate their protobuf code.

Is that the case here? And if so, what's protobuf's expectation for customers? Are compiler versions expected to be compatible with older generated protobuf code?

Thank you for the quick response.

@esrauchg
Copy link

esrauchg commented Feb 5, 2025

@Radnyx Can you advise on when this change in behavior to MSVC might reach end users? Is there an expected version that it'll be included in?

This isn't just about the generated code, but the "runtime" code too (for C++ we only support having an exact match between generated code and runtime version though so its a bit of an academic distinction in that case, but the difference is more relevant for other languages).

It will help inform the discussion about potentially doing backported point releases with this change to older LTS versions, or if it would be expected that users would just need to use a sufficiently new Protobuf version to be compatible with that MSVC version.

Thanks!

@Radnyx
Copy link
Author

Radnyx commented Feb 5, 2025

@esrauchg No expected version as we'd like to measure the impact first. Still deciding whether to let users "opt-in" to the conformant behavior.

We appreciate the willingness to either backport or expect users to upgrade. I'll message back shortly on our plan.

@Radnyx
Copy link
Author

Radnyx commented Feb 7, 2025

Alrighty, thanks for your patience. We've decided not to add the error soon. Conformance there is still a future goal though.
So in the meantime, it would be ideal to backport the __builtin_offsetof change to older LTS versions.

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

No branches or pull requests

4 participants