[cfe-dev] operator==, Changing order of evaluation to expose bugs

Sergio Martins via cfe-dev cfe-dev at lists.llvm.org
Sat Oct 10 11:46:17 PDT 2015


Hi,

Consider:
if (foo() == bar()) 

it's up to the compiler to decide if it calls foo() or bar() first, as the 
standard doesn't guarantee any order.

Is there a way to force clang to evaluate first the rhs ?

I want to compile Qt with "evaluate rhs first" and check that unit-tests still 
pass, then rebuild with "evaluate lhs first".

Recenty we found some Qt code that relied on the order (undefined behavior) 
and it was discovered by compiling the code with MSVC2010, which evaluated the 
rhs first.


Regards,
Sérgio Martins




More information about the cfe-dev mailing list