1 | initial version |
This is an error in OpenCV. The macros CV_IMAX3 and CV_IMIN3 both refer to a temporary variable temp3. Later, these macros are used in code like the following:
if( ( CV_IMAX3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] ) - CV_IMIN3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] ) ) >= ICV_BIRCH_DIFF_LUM ) . . .
which has the form
if ( (expr1 - expr2 ) >= ICV_BIRCH_DIFF_LUM) . . .
The C++ language makes no guarantee about the order in which expr1 and expr2 will be evaluated. In fact, the computations could even be interwoven. Because expr1 and expr2 both alter (i.e. have side effects on) and use temp3, the result is not well-defined.
In my code, I replaced the #define directives in dpstereo.cpp with
For reference, this type of issue is covered the C++11 standard in section 1.9, starting in paragraph 13. Search for "sequenced before." This concept used to be described as "sequence points" in previous C++ standards. The effect of "sequence points" is still in C++11, but it was decided to drop the term and explain the behavior in-text.
This issue might not show up in other compilers because Clang tends to be more thorough in its error checking.