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

Warnings with Protobuf headers and MSVC #12675

Closed
coryan opened this issue May 5, 2023 · 0 comments
Closed

Warnings with Protobuf headers and MSVC #12675

coryan opened this issue May 5, 2023 · 0 comments
Assignees

Comments

@coryan
Copy link
Contributor

coryan commented May 5, 2023

What version of protobuf and what language are you using?

Version: 22.x but I think the problem is also in main
Language: C++

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

Windows

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

MSVC 2019 or MSVC 2022

What did you do?

Compiled some generated protos with /WX /W4, this is analogous to -Wall -Werror with GCC or Clang.

What did you expect to see

A successful compilation.

What did you see instead?

A compilation warning. As I have enabled "warnings as errors" it breaks the build.

# Configuration: f149506ea002c5503763e19bb7f79693d083f873032cd55c19002b510a750b73
# Execution platform: @local_config_platform//:host
bazel-out/x64_windows-opt/bin/external/com_google_protobuf/src/google/protobuf/_virtual_includes/arena_align\google/protobuf/arena_align.h(102): error C2220: the following warning is treated as an error
bazel-out/x64_windows-opt/bin/external/com_google_protobuf/src/google/protobuf/_virtual_includes/arena_align\google/protobuf/arena_align.h(102): warning C4146: unary minus operator applied to unsigned type, result still unsigned
bazel-out/x64_windows-opt/bin/external/com_google_protobuf/src/google/protobuf/_virtual_includes/arena_align\google/protobuf/arena_align.h(145): warning C4146: unary minus operator applied to unsigned type, result still unsigned
bazel-out/x64_windows-opt/bin/external/com_google_protobuf/src/google/protobuf/_virtual_includes/arena_align\google/protobuf/arena_align.h(159): warning C4146: unary minus operator applied to unsigned type, result still unsigned
bazel-out/x64_windows-opt/bin/external/com_google_protobuf/src/google/protobuf/_virtual_includes/protobuf_lite\google/protobuf/arena.h(300): note: see reference to function template instantiation 'T *google::protobuf::internal::ArenaAlign::Ceil<void>(T *) const' being compiled
        with
        [
            T=void
        ]
INFO: From Action external/com_google_googleapis/google/cloud/certificatemanager/v1/certificate_issuance_config.grpc.pb.h:

Anything else we should know about your project / environment

I usually try to workaround these problems by disabling the warning when including external headers, but I have not been very successful this time. If at all possible consider patching the headers.

You can repro the problem using godbolt:

https://godbolt.org/z/ces8Y7EPb

Changing the alignment to an int works:

https://godbolt.org/z/e837Kz6fc

Adding some casts also works:

https://godbolt.org/z/9M44v7bc6

Note that the same problem appears in 3 places in the code:

https://github.com/protocolbuffers/protobuf/blob/0ae328929ee2b6378d8cb3bb2c26700922098910/src/google/protobuf/arena_align.h#LL101C1-L103C4

constexpr size_t Ceil(size_t n) const { return (n + align - 1) & -align; }

and

return reinterpret_cast<T*>((intptr + align - 1) & -align);

That is the "fixes" are more like "proof-of-concepts" or "sketches".

@coryan coryan added the untriaged auto added to all issues by default when created. label May 5, 2023
@shaod2 shaod2 added c++ windows and removed untriaged auto added to all issues by default when created. labels May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants