Discussion:
gcc vs g++ warnings
Martin Ettl
2009-06-12 12:32:42 UTC
Permalink
Hello,

compiled my application with gcc-4.3.3 on Ubuntu Linux. I also compiled it with g++-4.3.3 and got the following issue.

I created the following testcase:

#define SR_MULT (11*12)
#define A(x) (x) ? (SR_MULT/x) : 0
static const unsigned char sr_adc_mult_table[] = {
A(2), A(2), A(12), A(12), A(0), A(0), A(3), A(1),
A(2), A(2), A(11), A(11), A(0), A(0), A(0), A(1)
};

int main()
{}


My compiler says:

$ g++ -o test test.cpp
test.cpp:4: warning: division by zero
test.cpp:4: warning: division by zero
test.cpp:5: warning: division by zero
test.cpp:5: warning: division by zero
test.cpp:5: warning: division by zero


g++ -v

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3
--program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)

gcc does not warn about this. What happens, is this a bug in the compiler?


Regards

Martin
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
Ian Lance Taylor
2009-06-12 22:03:18 UTC
Permalink
Post by Martin Ettl
compiled my application with gcc-4.3.3 on Ubuntu Linux. I also compiled it with g++-4.3.3 and got the following issue.
#define SR_MULT (11*12)
#define A(x) (x) ? (SR_MULT/x) : 0
static const unsigned char sr_adc_mult_table[] = {
A(2), A(2), A(12), A(12), A(0), A(0), A(3), A(1),
A(2), A(2), A(11), A(11), A(0), A(0), A(0), A(1)
};
int main()
{}
$ g++ -o test test.cpp
test.cpp:4: warning: division by zero
test.cpp:4: warning: division by zero
test.cpp:5: warning: division by zero
test.cpp:5: warning: division by zero
test.cpp:5: warning: division by zero
...
Post by Martin Ettl
gcc does not warn about this. What happens, is this a bug in the compiler?
I'm not sure that I would call it a bug, exactly. It's more of a
missing feature in the C++ frontend. When the C frontend sees code like
0 ? (121 / 0) : 0
it suppresses certain warnings about in the "(121 / 0)" part, since that
will never be executed. The C++ frontend does not have that feature.
Coincidentally, I just proposed a patch to fix this in the C++ frontend.
http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01001.html

Ian

Loading...