http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55885
Bug #: 55885
Summary: Modulo operator crashes for int and long variables if
they have minimal value
Classification: Unclassified
Product: gcc
Version: 4.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
Error description in source file
-------------------------------------
Compiled with
-------------------------------------
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658)
(LLVM build 2336.11.00) on MAC OS X Version 10.7.5 (Lion)
-------------------------------------
Result of gcc -v:
-------------------------------------
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/src/configure
--disable-checking --enable-werror
--prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2
--mandir=/share/man --enable-languages=c,objc,c++,obj-c++
--program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/
--with-slibdir=/usr/lib --build=i686-apple-darwin11
--enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/dst-llvmCore/Developer/usr/local
--program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11
--target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
-------------------------------------
Compiler and linker output
-------------------------------------
make all
Building file: ../src/iotest.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -Wextra -c -fmessage-length=0 -MMD -MP -MF"src/iotest.d"
-MT"src/iotest.d" -o "src/iotest.o" "../src/iotest.cpp"
Finished building: ../src/iotest.cpp
Building target: iotest
Invoking: MacOS X C++ Linker
g++ -o "iotest" ./src/iotest.o
Finished building target: iotest
-------------------------------------
Compiling with options -fno-strict-aliasing -fwrapv does not make a difference
-------------------------------------
file: iotest.cpp
-------------------------------------
#include <iostream>
#include <limits>
// Assumption: If a is a signed variable, then a % -1 should always be 0
//
// ok if myType is of type char or short
// fails if myType is of type int or long
int main() {
typedef int myType;
myType c;
myType a = std::numeric_limits<myType>::min();
int b = -1;
// always ok
c = a % -1;
std::cout << a << ", " << b << ", " << c << std::endl;
// signals EXC ARITHMETIC:Arithmetic exception
// if myType is int or is long
c = a % b;
std:: cout << a << ", " << b << ", " << c << std::endl;
return 0;
}