Catch (...) swallowing all other catches in xcode llvm 3.0
I am trying to run googletest for my C ++ project and some of that involves using EXPECT_THROW(statement, expected_exception);
. I am using XCode with "Apple LLVM Compiler 3.0" selected. All of this on Snow Leopard 10.6.8, XCode 4.2.
I could not pass any of these tests even when using an explicit bogus case EXPECT_THROW(throw std::runtime_error(), std::runtime_error);
After expanding the macro (from gtest / internal / gtest-internal.h: 1114 GTEST_TEST_THROW_) to
bool gtest_caught_expected = false;
try {
// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement);
throw std::runtime_error("sigh");
}
// catch (expected_exception const&) {
catch (std::runtime_error const& e){
std::cout << "const ref caught" << std::endl;
gtest_caught_expected = true;
}
// added by me to check it wasn't a const& issue
catch (std::runtime_error e){
std::cout << "type caught" << std::endl;
gtest_caught_expected = true;
}
catch (...) {
//gtest_msg.value =
// "Expected: " #statement " throws an exception of type "
//#expected_exception ".\n Actual: it throws a different type.";
//goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__);
std::cout << "unknown caught" << std::endl;
}
and then setting a breakpoint in gdb with catch catch
and walking through it, I see what is catch(runtime_errors)
missed and executed catch(...)
. If I comment out the block catch(...)
, then the correct statement is executed catch(std::runtime_error const& e)
.
Setting my compiler to "LLVM GCC 4.2" fixes the problem, but I want to target clang ++.
My separate test case EXPECT_THROW works when compiled manually with clang ++ on the command line, so I believe it must be some kind of esoteric xcode or llvm? Or maybe some of them like LLVM is a monkey torturing my runtime_error with some other type? I tried catch throw
but could get the type information in this context.
Has anyone experienced this before or have any ideas?
EDIT:
So, I also linked to libprofile_rt.dylib along with the compiler flags -fprofile-arcs -fprofile-coverage
. Removing the compiler flag -fprofile-arcs
fixed the problem. Annyoing because it crashes my coverage reports.
(The link to librpofile_rt.a had the same problems)
Of course, I'm not the only one who sees this, since LLVM allegedly uses googletest for its test sites ?!
Not sure if I should post this as an answer or if someone more knowledgeable can come along and provide a real solution.
source to share
After waiting, it looks a bit like there is no known fix for this, so I'll post my answer as above. It can be fixed in Xcode 4.3
So, I also linked with libprofile_rt.dylib as well as the compiler flags -fprofile-arcs -fprofile-coverage. Removing the -fprofile-arcs compiler flag fixed the problem. Annyoing because it crashes my coverage reports.
(The link to librpofile_rt.a had the same problems)
Of course, I'm not the only one who sees this, since LLVM allegedly uses googletest for its test sites ?!
source to share