【发布时间】:2017-01-08 18:41:28
【问题描述】:
这是测试代码。
#include <string>
int main(int argc, char const *argv[]) {
std::string a = "hello";
std::string b = "world";
return 0;
}
我是通过命令编译的:
clang++ test.cpp -g
然后我尝试调试它:
lldb a.out
在a = "hello" 运行之后,我在第 4 行添加了中断。我尝试通过p a 打印a,它显示以下错误:
error: incomplete type 'string' (aka 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >') where a complete type is requ
ired
note: forward declaration of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >'
error: 1 errors parsing expression
我想不通。
虽然我尝试用g++编译,但是没问题。
【问题讨论】:
-
一个疯狂的猜测 - 编译器对其进行了优化,因为它未使用,然后不包括类型定义(因为它们“不再需要”)。现在调试器无法访问它们。
-
你在电脑上测试过吗?这只是发生在我身上吗?