用于为基于模板的代码生成高质量错误消息的工具? [英] Tools to generate higher-quality error messages for template-based code?

查看:93
本文介绍了用于为基于模板的代码生成高质量错误消息的工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概念(使这些工具不必要)是不属于C ++ 11

Concepts, that would render these tools unnecessary, are not part of C++11.


  • STLFilt 本来是一个选项,但不再维护。

  • STLFilt would have been one option but it is no longer maintained.

C ++ 11的功能,但rel = nofollow noreferrer> Clang 声称可以提供富有表现力的诊断尚不可用。

Clang claims to give expressive diagnostics although important C++11 features are not available yet.

colorgcc 自1999年以来似乎已被废弃。

colorgcc seems to be abandoned since 1999.

可以使用哪些生产质量工具来解密错误消息源于基于模板的代码? Eclipse-CDT支持也很好。 :)

What production quality tools are available to decipher error messages stemming from template-based code? Eclipse-CDT support would be nice too. :)

如果我放弃使用C ++ 11,我对C ++ 98有什么选择?

If I give up on C++11, what options do I have for C++98?

相关问题:

  • Deciphering C++ template error messages
  • Improving g++ output

推荐答案

让我们对答案有一个刺(我将其标记为社区Wiki,因此我们可以得到很好的响应)...

Let's have a stab at an answer (I marked this community wiki so we get a good response together)...

我一直在使用模板,并且在某种程度上,错误消息通常已经有所改进:

I'm working since a long time with templates and error messages have generally improved in some way or another:


  • 写一堆错误会产生更多的文本,但通常还包括用户正在查看的级别,并且通常包括提示实际的问题是什么。既然编译器只看到一个翻译单元被扔掉,那么要确定堆栈中哪个错误最适合用户的错误并没有很多事情要做。

  • 使用概念检查器,即行使模板参数的所有必需成员并可能使用 static_assert()生成错误消息的类或函数,为模板作者提供了一种向用户告知假设的方法

  • 向用户介绍他编写的类型,而不是扩展所有typedef,因为编译器希望在最低级别看到这些信息也有帮助。 clang在这方面相当擅长,实际上会给您错误消息,例如谈论 std :: string 而不是将事物类型扩展到最终的结果。

  • Writing a stack of errors creates a lot more text but also typically includes the level the user is looking at and this generally includes a hint at what the actual problem is. Given that the compiler only sees a translation unit tossed at it, there isn't a lot which can be done determining which error in the stack is the one most suitable for the user.
  • Using concept checkers, i.e. classes or functions which exercise all the required members of template arguments and possibly generating errors messages using static_assert() give the template author a way to tell users about assumptions which apparently don't hold.
  • Telling the user about types he writes rather than expanding all typedefs as the compiler like to see at the lowest level also helps. clang is rather good at this and actually gives you error messages e.g. talking about std::string rather than expanding things type to whatever it ends up to be.

该技术的组合实际上导致例如clang产生相当不错的错误消息(即使它还没有实现C ++ 2011;但是,据我所知gcc和clang一直领先,没有编译器会这样做)。我知道其他编译器开发人员会积极致力于改善模板错误消息,因为许多程序员发现模板实际上是一个巨大的飞跃,即使错误消息需要一点时间才能习惯。

A combination of the technique actually causes e.g. clang to create quite decent error message (even if it doesn't implement C++2011, yet; however, no compiler does and as far as I can tell gcc and clang are leading the pack). I know other compiler developers actively work on improving the template error messages as lots of programmers have discovered that templates actually are a huge leap forward even though the error messages are something which takes a bit of getting used to.

像stlfilt face这样的问题工具是C ++编译器和库正在积极开发中。这会导致错误消息始终偏移,导致该工具接收不同的输出。尽管编译器作者致力于改善错误消息是一件好事,但是对于尝试使用收到的错误消息进行工作的人员来说,无疑会使工作变得更加艰难。这还有另一面:一旦检测到某个错误模式是常见的并被拾取,例如通过stlfilt(据我所知,它并没有得到积极维护),编译器作者可能希望直接按照这些模式报告错误,可能还为编译器提供了可用的其他信息,但以前并未提供。换句话说,我希望编译器编写者会接受用户描述常见错误情况以及如何最好地报告它们的报告。编译器编写者自己可能不会遇到错误,因为他们正在处理的代码实际上是C(例如,gcc在C中实现),或者因为他们习惯于某些模板技术,从而避免了某些错误(例如,省略了 typename 用于依赖类型)。

One problem tools like stlfilt face is that C++ compilers and libraries are under active development. This results in error messages shifting all the time, causing the tool to receive different outputs. While it is good that compiler writers work on improving error messages, it certainly makes life harder for people who try to work from the error messages they got. There is another side to this as well: once a certain error pattern is detected to be common and is picked up e.g. by stlfilt (well, it isn't actively maintained as far as I know) compiler writers are probably keen to report the errors following these patterns directly, possibly also providing additional information available to the compiler but not emitted before. Put differently, I would expect that compiler writers are quite receptive to reports from users describing common error situations and how they are best reported. The compiler writers may not encounter the errors themselves because the code they are working on is actually C (e.g. gcc is implemented in C) or because they are so used to certain template techniques that they avoid certain errors (e.g. omission of typename for dependent types).

最后,要解决有关具体工具的问题:我在何时使用的主要工具我有点纠结于编译器,抱怨某些模板实例化是使用不同的编译器!虽然并非总是如此,但通常一个编译器会报告完全无法理解的错误消息,只有在看到另一个编译器的简洁报告后才有意义(如果您感兴趣,我会定期使用最新版本的gcc,clang和EDG为了这)。不过,我不知道有像stlfilt这样容易打包的东西。

Finally, to address the question about concrete tools: the main "tool" I'm using when I get kind of stuck with a compiler complaining about some template instantiation is to use different compilers! Although it isn't always the case but often one compiler reports an entirely incomprehensible error messages which only makes sense after seeing the fairly concise report from another compiler (in case you are interested, I regularly use recent version of gcc, clang, and EDG for this). I'm not aware of a readily packaged too like stlfilt, however.

这篇关于用于为基于模板的代码生成高质量错误消息的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆