boost::format warning
Hello, when compiling a simple test like this: #include <boost/format.hpp> int main(void) { int c = 0; boost::format("%1% %2%") % (c==42) % c++; } with this command: $ c++ -c -O -Wall -o ftest.o ftest.cc I get this warning: ftest.cc: In function ‘int main()’: ftest.cc:4: warning: operation on ‘c’ may be undefined What did I do wrong? Thanks for the help! Henning $ c++ -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu8) $ uname -a Linux treponema 2.6.31-17-generic #54-Ubuntu SMP Thu Dec 10 16:20:31 UTC 2009 i686 GNU/Linux
El 15/01/2010 05:35 p.m., Henning Meyer escribió:
Hello,
when compiling a simple test like this:
#include <boost/format.hpp> int main(void) { int c = 0; boost::format("%1% %2%") % (c==42) % c++; }
with this command: $ c++ -c -O -Wall -o ftest.o ftest.cc
I get this warning: ftest.cc: In function ‘int main()’: ftest.cc:4: warning: operation on ‘c’ may be undefined
What did I do wrong?
Its implementation defined whether the evaluation of c==42 will happen before or after the evaluation of c++. I am happy to see a compiler that does emit a warning on this kind of code. Simply modify your code like this boost::format("%1% %2%") % (c==42) % c; c++; or this c++; boost::format("%1% %2%") % (c==42) % c; depending on what you actually intended. More on the subject here: http://talesofcpp.blogspot.com/2009/10/episode-ten-natural-order-of-things.h... K-ballo.-
Its implementation defined whether the evaluation of c==42 will happen before or after the evaluation of c++. I am happy to see a compiler that does emit a warning on this kind of code. Simply modify your code like this boost::format("%1% %2%") % (c==42) % c; c++; or this c++; boost::format("%1% %2%") % (c==42) % c; depending on what you actually intended.
More on the subject here: http://talesofcpp.blogspot.com/2009/10/episode-ten-natural-order-of-things.h...
Thanks for pointing this out. And sorry to spam the boost mailing list, for this unrelated question (as I know now). Henning
participants (2)
-
Agustín K-ballo Bergé
-
Henning Meyer