This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80744] Detect Divide By Zero and give a warning in C/C++
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 02 Aug 2018 16:41:22 +0000
- Subject: [Bug c++/80744] Detect Divide By Zero and give a warning in C/C++
- Auto-submitted: auto-generated
- References: <bug-80744-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80744
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
I agree that diagnosing (A) or (C) under -Wdiv-by-zero would not be appropriate
because the option controls compile-time division by zero and there is none
here.
Extending -Wdiv-by-zero to diagnose possible division by zero would undoubtedly
make the option exceedingly noisy. Introducing a new option such as
-Wmaybe-div-by-zero analogous to -Wmaybe-uninitialized would be fine but the
option wouldn't diagnose ether (A) or (C) because there is no evidence of
overflow. -Wmaybe-uninitialized triggers under very restrictive conditions,
when there is some evidence that an uninitialized variable is used. To avoid
excessive noise from -Wmaybe-div-by-zero some similar approach would need to
used. Such as:
int f (int i)
{
int j;
if (i == 0) // because of this test
j = 7;
else
j = 13;
return j / i; // i may be assumed to be zero here
}