gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:38:31 30 4
gpt4 key购买 nike

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

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

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

最佳答案

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

来自他们的网站:

STLFilt was initially conceived as a teaching aid, to allow students taking C++ and/or STL-specific workshops to make sense of typically overbloated STL error messages. Today, however, even some C++ experts have adopted STLFilt for use in everyday development. The results may not always be perfect, but most of the time the information lost during Decryption is not critical to the application being debugged. The rest of the time, Decryption is easy enough to bypass.

The distribution for each platform (compiler/library set) is self-contained and tuned to the idiosyncrasies of that platform. Each Perl script performs basic regex substitutions for all the standard (and extended, if present in the library) STL components, while certain versions of the script go further with respect to message ordering, line wrapping, library header error treatment, etc., as I unilaterally deemed appropriate for that platform.

这里是 a demo run这表明它是如何有用的:

The source program:

#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;
}

First, an unfiltered run using the MinGW gcc 3.2 compiler:

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 *
'

And a filtered run using the gcc-specific Proxy 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

[Note: demo runs were performed in an 80-column console window with STLFilt's intelligent line wrapping enabled, and with internal switches set to produce messages as terse as possible. More detail is available by tailoring the Decryptor's options.]

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

这里是 a relevant journal article由 STLFilt 的作者撰写。

关于c++ - 如何处理太长的 STL 模板错误报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7974544/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com