简体   繁体   English

用于禁用C ++“功能”的编译器选项

[英]Compiler options to disable C++ “features”

Is it possible to pass a compiler (eg, g++, clang, etc.) flags or defines that will disable certain “features” of C++ as a means of quality control? 是否可以通过编译器(例如,g ++,clang等)标志或定义将禁用C ++的某些“功能”作为质量控制的手段?

I'd love to disable multiple inheritance and a lot of other things in C++ that (I think) do more harm than good. 我想在C ++中禁用多重继承和许多其他东西(我认为)弊大于利。

Once you've selected C++ as your language you get C++ as your language. 一旦您选择C ++作为您的语言,您就可以使用C ++作为您的语言。 The compiler can't legitimately start rejecting legal C++ programs as a result of some configuration flag. 由于某些配置标志,编译器无法合法地开始拒绝合法的C ++程序。

So one obvious option is to not use C++ but instead pick a language that provides the features and safety considerations that you're interested in. 因此,一个显而易见的选择是不使用C ++,而是选择一种语言来提供您感兴趣的功能和安全注意事项。

If you do elect to continue with C++ then understand that the language allows you to shoot yourself in the foot. 如果您确实选择继续使用C ++,那么请理解该语言可以让您自己动手。 This is by design . 这是设计的

What you can do is hold design reviews, code reviews, and utilize static code checkers and compiler warnings to catch a wide variety of problems at various stages of development. 您可以做的是进行设计审查,代码审查,并利用静态代码检查器和编译器警告来捕获各个开发阶段的各种问题。

You might perhaps customize GCC, eg with MELT , to add your additional coding rules validation. 您可以自定义GCC,例如使用MELT ,以添加额外的编码规则验证。 However, this is not trivial (probably months of work, even for me, the main author of MELT). 然而,这不是微不足道的(可能是几个月的工作,即使对我来说,也是MELT的主要作者)。 Such an hypothetical extension of GCC would emit some of the warnings you want. GCC的这种假设扩展会发出一些你想要的警告。

So the flags you'll pass will probably start with -fplugin=melt ; 所以你传递的旗帜可能会以-fplugin=melt开头; but some additional work is needed (to implement your required GCC extensions in MELT). 但还需要一些额外的工作(在MELT中实现所需的GCC扩展)。

PS. PS。 If you are serious enough to be able to put (or buy) months of work around that idea, please contact me. 如果你足够认真,能够围绕这个想法投入(或购买)数月的工作,请与我联系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM