在我的C代码中,我经常使用模板..这可能是轻描淡写.最终结果是类型名称占用超过4096个字符,并且至少可以看到GCC输出是痛苦的.
在像GDB或Valgrind这样的几个调试包中,可以请求不对C类型进行解码.有没有类似的方法强制G只输出损坏的类型名称,削减所有不必要的输出?
澄清
由于给出了第一个答案,我发现问题不明确.考虑以下MWE:
template <typename T> class A { public: T foo; }; template <typename T> class B { }; template <typename T> class C { public: void f(void) { this->foo = T(1); this->bar = T(2); } }; typedef C< B< B< B< B< A<int> > > > > > myType; int main(int argc,char** argv) { myType err; err.f(); return 0; };
行中的错误 – > bar = T(2);仅当类型为C< myType>的对象时才会出错实例化并调用方法C :: f().因此,G沿这些行返回错误消息:
test.cpp: In instantiation of ‘void C<T>::f() [with T = B<B<B<B<A<int> > > > >]’: test.cpp:33:8: required from here test.cpp:21:14: error: no matching function for call to ‘B<B<B<B<A<int> > > > >::B(int)’ this->foo = T(1); ^ test.cpp:21:14: note: candidates are: test.cpp:11:7: note: B<B<B<B<A<int> > > > >::B() class B ^ test.cpp:11:7: note: candidate expects 0 arguments,1 provided test.cpp:11:7: note: B<B<B<B<A<int> > > > >::B(const B<B<B<B<A<int> > > > >&) test.cpp:11:7: note: no known conversion for argument 1 from ‘int’ to ‘const B<B<B<B<A<int> > > > >&’ test.cpp:21:14: error: ‘class C<B<B<B<B<A<int> > > > > >’ has no member named ‘foo’ this->foo = T(1); ^ test.cpp:23:14: error: no matching function for call to ‘B<B<B<B<A<int> > > > >::B(int)’ this->bar = T(2); ^ test.cpp:23:14: note: candidates are: test.cpp:11:7: note: B<B<B<B<A<int> > > > >::B() class B ^ test.cpp:11:7: note: candidate expects 0 arguments,1 provided test.cpp:11:7: note: B<B<B<B<A<int> > > > >::B(const B<B<B<B<A<int> > > > >&) test.cpp:11:7: note: no known conversion for argument 1 from ‘int’ to ‘const B<B<B<B<A<int> > > > >&’ test.cpp:23:14: error: ‘class C<B<B<B<B<A<int> > > > > >’ has no member named ‘bar’ this->bar = T(2);
类型名称在这里很烦人,但是当完整的类型名称需要数百个字符时,无法读取.有没有办法向GCC询问损坏的类型名称而不是全名,或以某种方式限制其长度?
STLFilt
不幸的是,STLFilt只使输出更漂亮;长度不变.事实上,输出被分成多行的事实使整个事情变得更糟,因为输出占用更多空间.
解决方法
人们正在遭受C错误报告的这一特殊缺点.