This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52299] New: GCC warns on compile time division by zero erroneously
- From: "joseph.h.garvin at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 17 Feb 2012 19:11:02 +0000
- Subject: [Bug c++/52299] New: GCC warns on compile time division by zero erroneously
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: joseph.h.garvin@gmail.com
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).