【问题标题】:How to deal with way too long STL template error report?如何处理太长的 STL 模板错误报告?
【发布时间】:2011-12-19 22:43:02
【问题描述】:

当使用c++ STL 编程,或密集使用'模板化',并且发生一些编译错误时,错误报告通常很长,并且经常给出太多不需要的信息。 我说的是 gcc,我不知道是否与其他编译器不同,但有时即使只是一个错字,也需要一段时间才能捕捉到清除错误的错误

<ns::type<ns::type<ns::type, ns::type<...><ns::type<...> > > > >

我正在寻找一些编译器标志、技巧、解决方法或方法(我目前复制过去的错误并将我拥有的内容和编译器用于想要的内容和删除变量书签放在两行...(对于一个不常见的 ctrl+s 表现不佳))可以使这项任务更快或只是帮助我(甚至只有一些 IDE 错误语法突出显示...)

【问题讨论】:

  • 用另一个编译器编译通常非常非常有用。 gcc、Visual C++、基于 EDG 的编译器(如 Comeau 或 Intel C++)和 Clang 都会为模板编译错误生成非常不同的诊断消息。它们都有一些非常有用的诊断信息,它们都有一些完全没用的信息。如果您使用多个编译器进行编译,则更有可能获得更有用的诊断消息。
  • 嗯,我会试试的。我认为它们很标准,但不是很舒服。

标签: c++ templates stl


【解决方案1】:

STLFilt: An STL Error Message Decryptor for C++ 是一种流行的工具,可以过滤这些冗长的错误消息并将它们变成更清晰的内容。

来自他们的网站:

STLFilt 最初被设想为一种教具,让学生 参加 C++ 和/或特定于 STL 的研讨会以了解典型情况 过度膨胀的 STL 错误消息。然而,今天,即使是一些 C++ 专家 已采用 STLFilt 用于日常开发。结果可能 并不总是完美的,但大多数时候信息会丢失 在解密期间对被调试的应用程序并不重要。 其余时间,解密很容易绕过。

每个平台(编译器/库集)的发行版是 自包含并调整到该平台的特质。每个 Perl 脚本对所有标准执行基本的正则表达式替换 (和扩展,如果存在于库中)STL 组件,而 某些版本的脚本在消息方面走得更远 排序、换行、库头错误处理等,正如我 单方面认为适合该平台。

a demo run 说明了它的用途:

源程序:

#include <map>
#include <algorithm>
#include <cmath>

const int values[] = { 1,2,3,4,5 };
const int NVALS = sizeof values / sizeof (int);

int main()
{
    using namespace std;

    typedef map<int, double> valmap;

    valmap m;

    for (int i = 0; i < NVALS; i++)
        m.insert(make_pair(values[i], pow(values[i], .5)));

    valmap::iterator it = 100;              // error
    valmap::iterator it2(100);              // error
    m.insert(1,2);                          // error

    return 0;
}

首先,使用 MinGW gcc 3.2 编译器进行未经过滤的运行:

d:\src\cl\demo>c++2 rtmap.cpp
rtmap.cpp: In function `int main()':
rtmap.cpp:19: invalid conversion from `int' to `
   std::_Rb_tree_node<std::pair<const int, double> >*'
rtmap.cpp:19:   initializing argument 1 of `std::_Rb_tree_iterator<_Val, _Ref,
   _Ptr>::_Rb_tree_iterator(std::_Rb_tree_node<_Val>*) [with _Val =
   std::pair<const int, double>, _Ref = std::pair<const int, double>&, _Ptr =
   std::pair<const int, double>*]'
rtmap.cpp:20: invalid conversion from `int' to `
   std::_Rb_tree_node<std::pair<const int, double> >*'
rtmap.cpp:20:   initializing argument 1 of `std::_Rb_tree_iterator<_Val, _Ref,
   _Ptr>::_Rb_tree_iterator(std::_Rb_tree_node<_Val>*) [with _Val =
   std::pair<const int, double>, _Ref = std::pair<const int, double>&, _Ptr =
   std::pair<const int, double>*]'
E:/GCC3/include/c++/3.2/bits/stl_tree.h: In member function `void
   std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(_II,

   _II) [with _InputIterator = int, _Key = int, _Val = std::pair<const int,
   double>, _KeyOfValue = std::_Select1st<std::pair<const int, double> >,
   _Compare = std::less<int>, _Alloc = std::allocator<std::pair<const int,
   double> >]':
E:/GCC3/include/c++/3.2/bits/stl_map.h:272:   instantiated from `void std::map<_
Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _Input
Iterator = int, _Key = int, _Tp = double, _Compare = std::less<int>, _Alloc = st
d::allocator<std::pair<const int, double> >]'
rtmap.cpp:21:   instantiated from here
E:/GCC3/include/c++/3.2/bits/stl_tree.h:1161: invalid type argument of `unary *
   '

以及使用 gcc 特定的代理 c++ 过滤运行:

d:\src\cl\demo>c++ rtmap.cpp
  *** {BD Software Proxy c++ for gcc v3.01} STL Message Decryption is ON! ***
rtmap.cpp: In function `int main()':
rtmap.cpp:19: invalid conversion from `int' to `iter'
rtmap.cpp:19:   initializing argument 1 of `iter(iter)'
rtmap.cpp:20: invalid conversion from `int' to `iter'
rtmap.cpp:20:   initializing argument 1 of `iter(iter)'
stl_tree.h: In member function `void map<int,double>::insert_unique(_II, _II)':
    [STL Decryptor: Suppressed 1 more STL standard header message]
rtmap.cpp:21:   instantiated from here
stl_tree.h:1161: invalid type argument of `unary *'

STL Decryptor reminder:
    Use the /hdr:L option to see all suppressed standard lib headers

[注意:演示运行是在一个 80 列的控制台窗口中执行的 STLFilt 的智能换行启用,并具有内部 开关设置为尽可能简洁地生成消息。更多细节是 可以通过定制解密器的选项来获得。]

我能看到的唯一缺点是它错误地标记了 C++ 标准库。 :(

这里是 STLFilt 的作者 a relevant journal article

【讨论】:

  • 虽然理论上这可以回答这个问题,it would be preferable 在这里包含答案的基本部分,并提供链接以供参考。
  • @Kev:不过,也许应该为不正确的信息保留反对票,而不是“呈现不良”的信息。编辑:此外,这个类比甚至不适用于这个特定的问答。
  • @GMan - 当我查看旗帜时,我什至没有看到投票结果。但是,不鼓励仅提供链接的答案,我们希望看到它们带有用户可能期望在另一端看到的摘要的备份。它还为搜索引擎结果工厂添加了更多内容。
  • @Kev:我并不是说有一个总结不好,只是人们不应该反对它。
  • 由于未知原因,没有任何地方可以解释如何在没有编译器的情况下使用脚本——如果出现错误,显然不想用过滤器重新编译项目。所以,这里是:STLfilt 在 perl 中有一个脚本来过滤输出,命名为gSTLFilt.pl。它从输入中获取错误列表,并将结果抛出到输出;因此可以将错误保存到文件«errlog»,并使用命令cat errlog | perl gSTLFilt.pl
【解决方案2】:

一些人已经制作了工具来执行此操作,因为没有内置任何东西。 Google 上的吨,但返回最高结果:http://www.bdsoft.com/tools/stlfilt.html

应该兼容visual studio和gcc。

编辑::

我需要输入更少的内容才能及时获得输入 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-21
    • 1970-01-01
    • 2010-10-15
    • 2018-12-12
    • 1970-01-01
    • 2016-06-02
    • 2018-04-26
    • 1970-01-01
    相关资源
    最近更新 更多