GCC:减少输出中的模板名称
GCC: cutting down template names in output
在我的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;
};
只有当类型为C<myType>
的对象被实例化并且方法C::f()
被调用时,行this->bar = T(2);
中的错误才是错误。因此,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++错误报告的这一特殊缺陷。:)
但是,更详细的错误报告通常更适合解决复杂的问题。因此,一种更好的方法是让g++吐出长而详细的错误消息,然后使用独立的错误解析器来提高输出的可读性。
这里曾经有一个不错的错误分析器:http://www.bdsoft.com/tools/stlfilt.html(不幸的是,已不再开发)。
另请参阅此近乎重复的内容:解密C++模板错误消息
这永远不会奏效。当你制作模板类时:
B<A<int> >
这个类的定义中不再包含函数f()。如果你用clang++编译它,你会得到错误(其中测试类型为B<A<int> >
):
error: no member named 'f' in 'B<A<int> >'
test.f();
~~~~ ^
如果您想要更易读的错误,请尝试使用clang++。
您可以使用typedef
:
typedef queue<int> IntQueue;
显然,在这个例子中,您只删除了类型名称的2个字符,但对于更复杂的例子,这将缩小更多的字符,并提高代码的可读性。
此外,这可能有助于IDE的自动完成功能(如果您使用的话)。
- 编译器资源管理器和 GCC 具有不同的输出
- GCC 仪器 - 是否可以自动输出函数的参数?
- std::p ut_money在使用GCC时不输出零值
- GCC 预处理器输出和编译一次通过,v2
- 为什么 gcc 和 clang 各自为这个程序产生不同的输出?(转换运算符与构造函数)
- 为什么Visual Studio和GCC为C 代码产生不同的输出
- GCC 编译器对类型转换有什么作用?为什么 mac 和 Linux 上的输出不同
- GCC 8 交叉编译器输出 ARMv7 可执行文件而不是 ARMv6
- GCC -FROFILE -ARCS:如何在自定义RTO上输出文件
- ofstream在极其简单的程序(GCC/Code::Blocks)中首次输出时崩溃
- 如何隐藏外部标头'note: ... ' gcc 输出?
- GCC.obj文件输出不具有确定性(.debug_info,PROGPITS部分)
- Eclipse 不解析 gcc 输出
- GCC和MSVC之间的文件输出不一致
- 可视化GDB在MSVC2012和GCC 7.3.1之间打印不同的C++输出
- 如何在windows中的gcc中逐行读取命令输出,就像使用标准输入一样
- GCC:减少输出中的模板名称
- gcc 预处理的表单哈希符号 + 数字"# 1"输出行是什么意思?
- GCC编译器:编译具有不同输出文件名的多个文件
- 试图理解GCC-XML输出变量的含义