protocolbuffers / protocolbuffers/protobuf

Signed / unsigned comparison warning on MSVC

Open Beginner friendly
#15,028 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

c++ help wanted
Dominant language
C++
Stars
72k
Forks
16.3k
Avg merge
1d 17h
Merged PRs (30d)
140

Description

What version of protobuf and what language are you using?
Version: v25.1 (actually a bit after, main from 20231123. Relevant code hasn't changed since then)
Language: C++

What operating system (Linux, Windows, ...) and version?
Windows 11 Pro 22H2

What runtime / compiler are you using (e.g., python version or gcc version)
MS Visual Studio 17.8.0 (tool version 14.37.32822)

What did you do?
Compile something that makes use of include/google/protobuf/map.h

What did you expect to see
Warning-free compilation

What did you see instead?
Warnings from Abseil : include\absl\log\internal\check_op.h(340,1): warning C4018: '>=': signed/unsigned mismatch
This is from an Abseil macro that generates Check_GEImpl(), used in map.h

Anything else we should know about your project / environment

map.h line 1041 (in current main) invokes

ABSL_DCHECK_GE(new_num_buckets, kMinTableSize);

the first arg is map_index_t which resolves to uint32_t, whereas the second is defined
at line 528 as

enum { kMinTableSize = 16 / sizeof(void*) };

I'm guess MSVC is choosing a signed type for the enum which is causing the problem. Changing it to

enum : unsigned int { kMinTableSize = 16 / sizeof(void*) };

makes the warnings go away

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling a small C++ use of include/google/protobuf/map.h with MSVC and inspect map.h around lines 528 and 1041, where kMinTableSize is compared with map_index_t. Check the warning path through include/absl/log/internal/check_op.h:340. Done means the comparison compiles without MSVC signed/unsigned warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.