I am learning C++, and trying to write good code. I am currently using a lof of compiler flags, such as
-Wextra -Wall -pedantic -Werror -Wfatal-errors -Wcast-qual -Wcast-align -Wconversion -Wdouble-promotion -Wfloat-equal -Wshadow -Wpointer-arith -Weffc++ -ansi -Wstrict-aliasing
I have just learned that keywords new
and delete
should not be used anymore in C++11. However, I do not have any warnings when I use them.
Is there some flags to use to ensure a good C++11 style?
Compiler flags are options you give to gcc when it compiles a file or set of files. You may provide these directly on the command line, or your development tools may generate them when they invoke gcc. This section describes just the flags that are specific to Objective-C. -fconstant-string-class= ClassName.
You can use the -O2 flag to optimize and error check at the same time. For example, a student's code seem to be perfectly normal when compiling with the normal flags. # Before, compiled without errors $ g++ -Wall -std=c++17 main.
To see if your compiler has C++11 support, run it with just the --version option to get a print out of the version number. Do this for whichever compiler(s) you wish to use with Rosetta. Acceptable versions: GCC/g++: Version 4.8 or later.
First, you have to realize that your compiler is never going to completely enforce good style.
However, there are two techniques that you can use for the compiler to help you enforce your own style: warnings (which can be passed on the command line or in pragmas) and poison pragmas.
It is difficult, however, to manage the exact set of warnings that are available with each compiler version, so I made a list of warnings. Note that support for clang is minimal, its warnings are usually inferior to gcc's in practive, despite their fantastic marketing; additionally it is impossible to detect which version of clang you are using to work around bugs (feature detection macros are rather worthless).
I also made a list of poison.
Additionally, I have some makefile magic that ensures that the above two techniques are applied to every applicable file as well as doing some other checks.
It should be noted, however, that every application has different needs, so these headers should not be used as is. Very few applications, for example, would want to poison std::string
like I did.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With