如何使用clang ++与-std = c ++ 11 -Weverything -Werror [英] How to use clang++ with -std=c++11 -Weverything -Werror

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

问题描述

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

  #include< iostream& 

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

int main(){
std :: cout< 作品! << std :: endl;
return 0;
}



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



有一个错误:


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


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

解决方案

实际上,你可能不需要所有的警告,因为一些警告可以被认为是风格或主观的,而其他(例如你碰到的)只是愚蠢的你的情况。



-Weverything 最初是由于两个原因构建的:




  • 发现: c $ c>你樱桃挑选你不想申请的;优点是当转换到新版本的编译器时,您更有可能从新的警告中受益。



显然,是不是真的兼容生产使用;因此您似乎属于黑名单



Clang诊断系统将输出最默认的警告名称负责生成警告( -Wc ++ 98-compat )的每个警告组,并且可以通过添加 no-



因此,对于黑名单,您可以: p>

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



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


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

With the following command: clang++ temp.cpp -o temp -std=c++11 -Weverything -Werror

There is an error:

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

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 was initially built for two reasons:

  • 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 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).

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

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