[cfe-dev] Embedded conditionals not being evaluated correctly?
Michael Jackson
mike.jackson at bluequartz.net
Thu Jul 29 09:03:55 PDT 2010
I have code that looks something like this:
bool evaluate(int i, int j) { return (i < j) ? true : false; }
void function()
{
int i = 0;
int j = 1;
if ( evaluate(i, j) == true ) { }
else { std::cout << "This is BAD" << std::endl; }
}
when I compile this code with clang (latest SVN head) and then run it I will get
the "This is BAD" printed out which is obviously NOT correct. If I change the code
to introduce an intermediate variable:
bool b = evaluate(i,j);
if ( b == true ) { }
else { std::cout << "This is BAD" << std::endl; }
this this compiles and runs just fine.
The fun part in all of this is that I am unable to create a small reproducible test case
for a bug report. I have used the OS X 10.6 gdb to debug through the code and verify what
should really be going on and that the executable is NOT matching what should be happening.
If I compile my code with GCC then I get the expected results.
My question is simple: Are there known or questionable issues with clang++ and nested conditionals
that evaluate to C++ bool? I did some searches through the clang bugzilla but did not identify my problems.
The real code is part of a unit testing code base that I have. I have identified an workaround that seems
to let both clang and gcc produce the same test results but something does not sit right with that
solution.
Thanks for any help or comments.
___________________________________________________________
Mike Jackson www.bluequartz.net
Principal Software Engineer mike.jackson at bluequartz.net
BlueQuartz Software Dayton, Ohio
More information about the cfe-dev
mailing list