http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52299
Bug #: 52299
Summary: GCC warns on compile time division by zero erroneously
Classification: Unclassified
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
Test case:
template<std::size_t x>
struct test {
static const std::size_t a_
= x ? 10 / x : 10;
};
Output from compiling:
alignptrtest.cpp: In instantiation of ‘const size_t test<0ul>::a_’:
alignptrtest.cpp:11: instantiated from here
alignptrtest.cpp:6: warning: division by zero
The warning should be suppressed when zero is explicitly checked for. At
runtime this could require fancy analysis that might be unreasonable to expect,
but since this is compile time it should be possible to know whether the
division by 0 really occurs. Especially since it's smart enough to give the
warning even when dividing by (x+1-1).