如何在 -std=c++11 -Weverything -Werror 中使用 clang++

How to use clang++ with -std=c++11 -Weverything -Werror(如何在 -std=c++11 -Weverything -Werror 中使用 clang++)

本文介绍了如何在 -std=c++11 -Weverything -Werror 中使用 clang++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编译以下文件(temp.cpp):

I want to compile the following file (temp.cpp):

#include <iostream> 

class Foo {
public:
  Foo() = default;
};

int main(){
  std::cout << "Works!" << std::endl;
  return 0;
}

使用以下命令:clang++ temp.cpp -o temp -std=c++11 -Weverything -Werror

有一个错误:

temp.cpp:5:11: 错误:默认函数定义与 C++98 不兼容 [-Werror,-Wc++98-compat]

temp.cpp:5:11: error: defaulted function definitions are incompatible with C++98 [-Werror,-Wc++98-compat]

我知道有一个像 c++98-compat 这样的警告,它是一切的一部分.如何启用除 c++98-compat 之外的所有警告?-Weverything 是否有 C++11 兼容标志?

I understand that there is a warning like c++98-compat and it is part of everything. How can I enable all warnings except c++98-compat? Is there a c++11 compatible flag for -Weverything?

推荐答案

实际上,您可能不想要所有的警告,因为许多警告可以被认为是风格或主观的和其他的(例如您运行的警告)犯规)在你的情况下只是愚蠢的.

Actually, you probably do not want all the warnings, because a number of warnings can be considered as being stylistic or subjective and others (such as the one you ran afoul of) are just stupid in your situation.

-Weverything 最初的构建有两个原因:

-Weverything was initially built for two reasons:

  • 发现:否则很难获得所有可用警告的列表
  • 黑名单替代方案:使用 gcc,您可以挑选您希望应用的警告(白名单),使用 -Weverything 您可以挑选您不想应用的警告;优点是当迁移到新版本的编译器时,您更有可能从新警告中受益
  • discovery: it's pretty hard otherwise to get a list of all available warnings
  • black-listing alternative: with gcc, you cherry pick the warnings you wish to apply (white-listing), with -Weverything you cherry pick those you do not wish to apply; the advantage is that when moving over to a new version of the compiler, you are more likely to benefit from new warnings

显然,发现与生产使用并不真正兼容;因此,您似乎属于列入黑名单的情况.

Obviously, discovery is not really compatible with production use; therefore you seem to fall in the black-listing case.

Clang 诊断系统将输出(默认情况下)负责生成警告的最具体警告组的名称(此处为 -Wc++98-compat)并且每个警告组可以是通过在 -W 之后添加 no- 来关闭.

Clang diagnostics system will output (by default) the name of the most specific warning group that is responsible for generating a warning (here -Wc++98-compat) and each warning group can be turned off by adding no- right after the -W.

因此,对于列入黑名单,您将获得:

Therefore, for blacklisting, you get:

-Weverything -Wno-c++98-compat -Wno-...

我们鼓励您不时修改列入黑名单的警告列表(例如,当您升级到更新的编译器时).

And you are encouraged to revise the list of blacklisted warnings from time to time (for example, when you upgrade to a newer compiler).

这篇关于如何在 -std=c++11 -Weverything -Werror 中使用 clang++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 -std=c++11 -Weverything -Werror 中使用 clang++

基础教程推荐