crm*_*ore 8 c++ macos xcode gcc
升级到Xcode 3.2和Snow Leopard后,我的调试版本在运行时被破坏并失败.Stringstreams似乎不起作用.它们在发布模式下工作.
我把它缩小为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;
}
Run Code Online (Sandbox Code Playgroud)
字符串流插入应该有效,但是当使用GCC 4.2和_GLIBCXX_DEBUG时,'<<'运算符会抛出异常,并设置bad和fail位.
我已经尝试了这些结果的各种编译器和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++命令行)中Debug配置的默认值?
| 归档时间: |
|
| 查看次数: |
2753 次 |
| 最近记录: |