http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57132

             Bug #: 57132
           Summary: spurious warning: division by zero [-Wdiv-by-zero] in
                    if (m) res %=m;
    Classification: Unclassified
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: vincenzo.innoce...@cern.ch


the following code is "copied" from line 131 of
libstdc++v3//include/bits/random.h


cat divzero.cc 
using UI = unsigned int;
template<UI m, UI a>
struct mod{
  static UI calc(UI x) {
    UI res = a*x;
    if (m) res %=m;
    return res;
  }

};


#include<iostream>
int main() {
   std::cout << mod<3,2>::calc(7) << std::endl;
   std::cout << mod<0,2>::calc(7) << std::endl;

};
pb-d-128-141-131-94:bugs48 innocent$ c++  -std=c++11 divzero.cc -Wall 
divzero.cc: In instantiation of ‘static UI mod<m, a>::calc(UI) [with unsigned
int m = 0u; unsigned int a = 2u; UI = unsigned int]’:
divzero.cc:16:27:   required from here
divzero.cc:6:16: warning: division by zero [-Wdiv-by-zero]
     if (m) res %=m;
                ^
pb-d-128-141-131-94:bugs48 innocent$ c++ -v
Using built-in specs.
COLLECT_GCC=c++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin12.3.0/4.9.0/lto-wrapper
Target: x86_64-apple-darwin12.3.0
Configured with: ./configure --disable-multilib --disable-bootstrap
--enable-lto -disable-libitm --enable-languages=c,c++,fortran,lto --no-create
--no-recursion
Thread model: posix
gcc version 4.9.0 20130428 (experimental) [trunk revision 198366] (GCC)

Reply via email to