简体   繁体   中英

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?

I'd love to disable multiple inheritance and a lot of other things in C++ that (I think) do more harm than good.

Once you've selected C++ as your language you get C++ as your language. The compiler can't legitimately start rejecting legal C++ programs as a result of some configuration flag.

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.

If you do elect to continue with C++ then understand that the language allows you to shoot yourself in the foot. 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. However, this is not trivial (probably months of work, even for me, the main author of MELT). Such an hypothetical extension of GCC would emit some of the warnings you want.

So the flags you'll pass will probably start with -fplugin=melt ; but some additional work is needed (to implement your required GCC extensions in MELT).

PS. If you are serious enough to be able to put (or buy) months of work around that idea, please contact me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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