升級到Xcode 3.2和Snow Leopard後,我的調試版本在運行時被破壞並失敗。 Stringstreams似乎不起作用。他們在發佈模式下工作。C++ Debug版本在Snow Leopard中破解了Xcode
我已經縮小到GCC 4.2,OSX SDK 10.6和_GLIBCXX_DEBUG預處理器符號的組合。這些是新Xcode項目的調試配置的默認值。
這段代碼顯示問題:
#include <iostream>
#include <string>
#include <sstream>
int main (int argc, char * const argv[]) {
std::stringstream stream;
std::cout << " expected actual" << std::endl;
std::cout << "stream.bad: 0 " << stream.bad() << std::endl;
std::cout << "stream.fail: 0 " << stream.fail() << std::endl;
std::cout << "stream.eof: 0 " << stream.eof() << std::endl;
std::cout << "stream.good: 1 " << stream.good() << std::endl;
stream.exceptions(std::ios::badbit | std::ios::failbit | std::ios::eofbit);
try{
stream << 11; //< Does not work as expected (see output)
}catch (std::bad_cast &e) {
std::cout << "Unexpected bad_cast: " << e.what() << std::endl;
}catch(std::exception &e){
std::cout << "Unexpected exception: " << e.what() << std::endl;
}
std::cout << " expected actual" << std::endl;
std::cout << "stream.bad: 0 " << stream.bad() << std::endl;
std::cout << "stream.fail: 0 " << stream.fail() << std::endl;
std::cout << "stream.eof: 0 " << stream.eof() << std::endl;
std::cout << "stream.good: 1 " << stream.good() << std::endl;
std::cout << std::endl;
std::cout << "EXPECT: " << 11 << std::endl;
std::cout << "ACTUAL: " << stream.str() << std::endl;
std::cout << std::endl << "Done" << std::endl;
return 0;
}
的字符串流插入應該工作,但使用GCC 4.2和_GLIBCXX_DEBUG時,在「< <」運營商拋出一個異常,而壞的和失敗位設置。
我已經試過了以下結果的編譯器和SDK的各種組合: - 使用GCC 4.2,LLVM-GCC或CLANG與SDK 10.6不起作用。 - 使用GCC 4.2,LLVM-GCC或CLANG與SDK 10.5一起工作。 - 將GCC 4.0與SDK 10.5或10.6一起使用。
如果_GLIBCXX_DEBUG中斷或不支持(使用SDK 10.6和GCC 4.2),那麼爲什麼這是新項目(C++命令行)中調試配置的默認值?
當然,因爲GCC是開源的,你可以隨時修復它自己。 – Crashworks 2009-09-13 07:06:54
謝謝, 這是僅適用於Apple的GCC嗎?它適用於此版本的其他平臺。 如果不支持,那麼爲什麼它是XCode中的默認值? 蘋果是否在任何地方記錄這一點? – crmoore 2009-09-13 11:39:28
@cdespinosa,你有沒有說它不支持STL調試模式的任何來源。另外,我嘗試了OSX Lion,但它仍然無法正常工作。 – highBandWidth 2011-12-15 23:34:07