Fixes #1454.
Previous fix was incomplete, so added new tests, confirmed problem report, and added fixes.
All the tests now compile cleanly with g++ -pedantic -Wall -Wno-long-long (checked with gcc-4.4.1 and 3.4.4).