struggled during hours identify bug due invalid statement:
... assert( variable = -0.5 );
this should assert( variable == -0.5 );
: developer typo.
i'm compiling visual studio 2015, , work on having "0-warning compilation".
how such bad , dangerous statement compile no warning being reported compiler? there no compiler option can enable avoid this?
edit: bool b = ( variable = -0.5 )
not produce compiler warning
assignments within conditional expressions warned against if using /w4
compilation level, see see this.
so tested using online msvc compiler (i don't have vs 2015 on pc) on code:
//microsoft (r) c/c++ optimizing compiler version 19.00.23506 x86 #include <iostream> #include <cassert> int main(){ int a; if (a = 2){ std::cout << "hello, world!\n"; } assert(a = 3); }
and command line: source_file.cpp -o a.exe /ehsc /md /w4 /i c:\boost_1_60_0 /link /libpath:c:\boost_1_60_0\stage\lib
, both lines warned:
warning(s): source_file.cpp(9) : warning c4706: assignment within conditional expression source_file.cpp(12) : warning c4706: assignment within conditional expression
apparently qt header qglobal.h
disables warning using qt_warning_disable_msvc(4706)
under configurations.
Comments
Post a Comment