use decimal constants to avoid casting error with visual c /W4

"unary minus operator applied to unsigned type, result still unsigned"
pull/1/head
jieluo@google.com 10 years ago
parent 76b8a769ab
commit e6726e2150
  1. 4
      src/google/protobuf/compiler/cpp/cpp_helpers.cc
  2. 6
      src/google/protobuf/compiler/cpp/cpp_unittest.cc

@ -270,9 +270,9 @@ string Int64ToString(int64 number) {
// gcc rejects the decimal form of kint64min
if (number == kint64min) {
// Make sure we are in a 2's complement system.
GOOGLE_COMPILE_ASSERT(kint64min == GOOGLE_LONGLONG(-0x8000000000000000),
GOOGLE_COMPILE_ASSERT(kint64min == GOOGLE_LONGLONG(~0x7fffffffffffffff),
kint64min_value_error);
return "GOOGLE_LONGLONG(-0x8000000000000000)";
return "GOOGLE_LONGLONG(~0x7fffffffffffffff)";
}
return "GOOGLE_LONGLONG(" + SimpleItoa(number) + ")";
}

@ -159,7 +159,7 @@ TEST(GeneratedMessageTest, Int32StringConversion) {
TEST(GeneratedMessageTest, Int64StringConversion) {
EXPECT_EQ("GOOGLE_LONGLONG(971)", Int64ToString(971));
EXPECT_EQ("GOOGLE_LONGLONG(-2147483648)", Int64ToString(kint32min));
EXPECT_EQ("GOOGLE_LONGLONG(-0x8000000000000000)", Int64ToString(kint64min));
EXPECT_EQ("GOOGLE_LONGLONG(~0x7fffffffffffffff)", Int64ToString(kint64min));
EXPECT_EQ("GOOGLE_LONGLONG(9223372036854775807)", Int64ToString(kint64max));
}
@ -196,8 +196,8 @@ TEST(GeneratedMessageTest, Trigraph) {
TEST(GeneratedMessageTest, ExtremeSmallIntegerDefault) {
const unittest::TestExtremeDefaultValues& extreme_default =
unittest::TestExtremeDefaultValues::default_instance();
EXPECT_EQ(-0x80000000, kint32min);
EXPECT_EQ(GOOGLE_LONGLONG(-0x8000000000000000), kint64min);
EXPECT_EQ(~0x7fffffff, kint32min);
EXPECT_EQ(GOOGLE_LONGLONG(~0x7fffffffffffffff), kint64min);
EXPECT_EQ(kint32min, extreme_default.really_small_int32());
EXPECT_EQ(kint64min, extreme_default.really_small_int64());
}

Loading…
Cancel
Save