如何处理太长的STL模板错误报告?

jal*_*one 14 c++ templates stl

当在c ++ STL中编程,或者集中使用"模板化",并且发生一些编译错误时,错误报告通常很长,并且通常会给出太多不需要的信息.我在谈论gcc,我不知道与其他编译器有什么不同,但有时甚至只是一个错字,需要一段时间来捕捉错误清除

<ns::type<ns::type<ns::type, ns::type<...><ns::type<...> > > > >
Run Code Online (Sandbox Code Playgroud)

我正在寻找一些编译器标志,技巧,变通方法或方法(我目前复制过去的错误,并把我所拥有的两行和编译器用来想要和删除变量书签......(有点悲伤的程序,不是 - 如此不常见的ctrl + s表现不佳))可以让这个任务更快或者只是帮助我(甚至只有一些IDE错误语法突出显示......)

Lig*_*ica 11

STLFilt:用于C++的STL错误消息解密器是一种流行的工具,用于过滤这些详细的错误消息并将其转换为更易读的内容.

从他们的网站:

STLFilt最初被设想为一种教学辅助工具,允许学生参加C++和/或特定于STL的研讨会,以了解典型的过度STL错误信息.然而,今天,甚至一些C++专家已经采用STLFilt用于日常开发.结果可能并不总是完美的,但在解密过程中丢失信息的大部分时间对于正在调试的应用程序并不重要.其余的时间,解密很容易绕过.

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

这是一个演示运行,展示了它如何有用:

源程序:

#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;
}
Run Code Online (Sandbox Code Playgroud)

首先,使用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 *
   '
Run Code Online (Sandbox Code Playgroud)

并使用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
Run Code Online (Sandbox Code Playgroud)

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

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

这是STLFilt作者的相关期刊文章.

  • @Kev:我并不是说有一个总结是不可取的,只是因为人们不应该为此而低估. (3认同)
  • 由于未知原因无处解释如何在没有编译器的情况下使用脚本 - 显然,如果存在错误,则不希望使用过滤器重新编译项目.所以,这里是:`STLfilt`在perl中有一个脚本来过滤输出,命名为`gSTLFilt.pl`.它从输入中获取错误列表,并将结果抛出到输出; 所以可以将错误保存到文件«errlog»,并使用命令`cat errlog | perl gSTLFilt.pl` (3认同)