Address some `-Wsign-compare` warnings. Fixes #499. Change-Id: I076d4fb4a51e0589176fdd175045ac90b0e361cb Reviewed-on: https://code-review.googlesource.com/c/re2/+/63350 Reviewed-by: Paul Wankadia <junyer@google.com> Reviewed-by: Alex Chernyakhovsky <achernya@google.com>
diff --git a/BUILD.bazel b/BUILD.bazel index c765cfd..643d71f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel
@@ -135,6 +135,7 @@ ":re2", "@abseil-cpp//absl/base", "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/container:flat_hash_set", "@abseil-cpp//absl/flags:flag", "@abseil-cpp//absl/log:absl_check", "@abseil-cpp//absl/log:absl_log",
diff --git a/re2/bitmap256.h b/re2/bitmap256.h index e16a570..e303e71 100644 --- a/re2/bitmap256.h +++ b/re2/bitmap256.h
@@ -51,7 +51,7 @@ private: // Finds the least significant non-zero bit in n. static int FindLSBSet(uint64_t n) { - ABSL_DCHECK_NE(n, 0); + ABSL_DCHECK_NE(n, uint64_t{0}); #if defined(__GNUC__) return __builtin_ctzll(n); #elif defined(_MSC_VER) && defined(_M_X64)
diff --git a/re2/prog.cc b/re2/prog.cc index d3ff26e..9f1cc00 100644 --- a/re2/prog.cc +++ b/re2/prog.cc
@@ -37,13 +37,13 @@ // Constructors per Inst opcode void Prog::Inst::InitAlt(uint32_t out, uint32_t out1) { - ABSL_DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_out_opcode(out, kInstAlt); out1_ = out1; } void Prog::Inst::InitByteRange(int lo, int hi, int foldcase, uint32_t out) { - ABSL_DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_out_opcode(out, kInstByteRange); lo_ = lo & 0xFF; hi_ = hi & 0xFF; @@ -51,30 +51,30 @@ } void Prog::Inst::InitCapture(int cap, uint32_t out) { - ABSL_DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_out_opcode(out, kInstCapture); cap_ = cap; } void Prog::Inst::InitEmptyWidth(EmptyOp empty, uint32_t out) { - ABSL_DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_out_opcode(out, kInstEmptyWidth); empty_ = empty; } void Prog::Inst::InitMatch(int32_t id) { - ABSL_DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_opcode(kInstMatch); match_id_ = id; } void Prog::Inst::InitNop(uint32_t out) { - ABSL_DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_opcode(kInstNop); } void Prog::Inst::InitFail() { - ABSL_DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_opcode(kInstFail); } @@ -1113,7 +1113,7 @@ #if defined(__AVX2__) // Finds the least significant non-zero bit in n. static int FindLSBSet(uint32_t n) { - ABSL_DCHECK_NE(n, 0); + ABSL_DCHECK_NE(n, uint32_t{0}); #if defined(__GNUC__) return __builtin_ctz(n); #elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) @@ -1135,7 +1135,7 @@ #endif const void* Prog::PrefixAccel_FrontAndBack(const void* data, size_t size) { - ABSL_DCHECK_GE(prefix_size_, 2); + ABSL_DCHECK_GE(prefix_size_, size_t{2}); if (size < prefix_size_) return NULL; // Don't bother searching the last prefix_size_-1 bytes for prefix_front_.
diff --git a/re2/re2.cc b/re2/re2.cc index 2e25b64..5978035 100644 --- a/re2/re2.cc +++ b/re2/re2.cc
@@ -332,7 +332,7 @@ // Finds the most significant non-zero bit in n. static int FindMSBSet(uint32_t n) { - ABSL_DCHECK_NE(n, 0); + ABSL_DCHECK_NE(n, uint32_t{0}); #if defined(__GNUC__) return 31 ^ __builtin_clz(n); #elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
diff --git a/re2/regexp.cc b/re2/regexp.cc index 1e5ae90..f7e5ba2 100644 --- a/re2/regexp.cc +++ b/re2/regexp.cc
@@ -498,7 +498,7 @@ if (n == 0) break; - ABSL_DCHECK_GE(n, 2); + ABSL_DCHECK_GE(n, size_t{2}); a = stk[n-2]; b = stk[n-1]; stk.resize(n-2);