Fix compile warnings in TestStrings.cpp: "this decimal constant is unsigned only in ISO C90" / "integer constant is so large that it is unsigned"

NEW
Unassigned

Status

()

defect
10 years ago
7 years ago

People

(Reporter: dholbert, Unassigned)

Tracking

(Blocks 1 bug)

Trunk
x86
Linux
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [build_warning])

When building TestStrings.cpp, I get:
> xpcom/tests/TestStrings.cpp:697: warning: this decimal constant is unsigned only in ISO C90
> xpcom/tests/TestStrings.cpp:697: warning: this decimal constant is unsigned only in ISO C90
> xpcom/tests/TestStrings.cpp:700:41: warning: integer constant is so large that it is unsigned
> xpcom/tests/TestStrings.cpp:700: warning: this decimal constant is unsigned only in ISO C90
> xpcom/tests/TestStrings.cpp:700:228: warning: integer constant is so large that it is unsigned
> xpcom/tests/TestStrings.cpp:700: warning: this decimal constant is unsigned only in ISO C90

The blamed lines are:
> 697     test_appends(-2147483648, L)
and
> 700     test_appends(-9223372036854775808, LL)

(which, after expanding macros, will end up appending the "L" and "LL" to the numeric values)

These are the minimum 32-bit and 64-bit signed integer values.

According to the second post on this thread...
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/4f5ed69b31fd5e1e
...the problem is that, in "-2147483648", the "-" and the "2147483648" are evaluated separately.  And 2147483648 isn't a valid signed integer. (it's too large by 1)

Can we work around this somehow?  i.e. Perhaps we could test -MAX_VALUE rather than MIN_VALUE in these cases? (so that the MAX_VALUE on its own, separate from the "-", doesn't freak out the compiler)
The original test used PRInt64 min = LL_MinInt(), I assume that this was chosen to ensure that the entire range was tested.

Would using a cast instead of an assignment help?
Whiteboard: [build_warning]
You need to log in before you can comment on or make changes to this bug.