Invalid C++ Code Prevents Compilation With Clang (Bug #3191)


Added by Marcus Urban over 11 years ago. Updated over 11 years ago.


Status:Done Start date:2013-08-03
Priority:Normal Due date:
Assignee:Victor Kocheganov % Done:

0%

Category:legacy, contrib
Target version:2.4.7
Affected version:2.4.6 (latest release) Operating System:Mac OSX
Difficulty:Medium HW Platform:x64
Pull request:https://github.com/Itseez/opencv/pull/1228

Description

The file dpstereo.cpp contains some invalid C++ code and will not compile on newer versions of Clang. Although most compilers will not flag the error, the code is clearly not correct.

The specific problem occurs when the macros

#define CV_IMAX3(a,b,c) ((temp3 = (a) >= (b) ? (a) : (b)),(temp3 >= (c) ? temp3 : (c)))
#define CV_IMIN3(a,b,c) ((temp3 = (a) <= (b) ? (a) : (b)),(temp3 <= (c) ? temp3 : (c)))

are used in expressions like

CV_IMAX3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] ) - CV_IMIN3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] )

Macros do not have local variables, and CV_IMIN3 and CV_IMAX3 both use the variable temp3. Because the subtraction of primitive types does not establish a sequenced-before relation, the expressions substituted for CV_IMIN3 and CV_IMAX3 can be evaluated in either order. This would allow temp3 to be assigned different values depending on how the compiler evaluated the expression. To prevent this problem, C++ prohibits this "unsequenced" assignment.


Associated revisions

Revision e9b9a6fc
Added by kocheganovvm over 11 years ago

Fix unsequenced assignment (Bug #3191).

History

Updated by Victor Kocheganov over 11 years ago

Hello Marcus,

thank you for reporting the issue!
I'll handle it.

Regards,
Victor Kocheganov

  • Category set to legacy, contrib
  • Status changed from New to Open
  • Pull request set to https://github.com/Itseez/opencv/pull/1228
  • Target version set to 2.4.7
  • Assignee set to Victor Kocheganov

Updated by Victor Kocheganov over 11 years ago

  • Status changed from Open to Done

Also available in: Atom PDF