-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Warnings with Protobuf headers and MSVC #12675
Description
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:
protobuf/src/google/protobuf/arena_align.h
Line 145 in 0ae3289
| constexpr size_t Ceil(size_t n) const { return (n + align - 1) & -align; } |
and
protobuf/src/google/protobuf/arena_align.h
Line 159 in 0ae3289
| return reinterpret_cast<T*>((intptr + align - 1) & -align); |
That is the "fixes" are more like "proof-of-concepts" or "sketches".