Can we add/remove coding standards to CppCheck? - cppcheck

Can we add some of the coding standards which is not defined in Cppheck, or can we remove some of the coding standards defined in Cpppcheck which i does not want to check.

It is impossible to tailor the code standards by changing some configuration. But if you modify the source code of Cppcheck, you can do it.

Related

How is C++ syntactic evolution managed?

Separate from frontend implementers' experiences, are there formal standards that syntactic extensions to the C++ grammar are required to meet? That is, are proposed extensions subjected to any form of mechanical analysis before being accepted?
I ask because I have read that the two most widely used C++ compilers, g++ and clang, both use hand written, recursive descent parsers. Does that mean that as the grammar evolves, it needs to remain LL(1) (or maybe LL(n)) with the proviso that certain implementation tricks are allowed / assumed / expected?
The C++ standard defines a language; it does not restrict what that language might become in the future. (The C standard does contain a section called "future directions", but that is more a warning to users of features which have been deprecated, and which identifiers might be reserved in the future, rather than being a limitation on future standards.)
That said, the standards process is basically conservative, since the committee includes representatives of the major compilers as well as major user groups, none of whom are likely to accept changes which make the language even harder to parse.
As far as I know, there is no mechanical validation of proposed changes. But there is a lot of manual analysis by people with a lot of experience and expertise. Moreover, proposed changes are generally accompanied by proof-of-concept implementations to demonstrate their viability and utility.

Is there any C++ coding standard like PSR-1/2

I was searching for C++ coding standard.
I found lots of standards:
Google C++ Style Guide
High Integrity C++ Coding Standard Version 4.0
...
Is there any C++ coding standard like PSR-1/21 that every C++ developer follows?
1) PHP Standard Recommendation. PSR-1: Basic Coding Standard. PSR-2: Coding Style Guide.
Is there any C++ coding standard like PSR-1/2 that every C++ developer follows?
The C++ language standard is made official by the ISO C++ Committee.
The standard comes with iterations and versionings (like c++-11, c++-14, c++-17) that are (mostly) backwards compatible.
That's actually what every C++ developer needs to follow.
If you're actually asking about coding style guides, that's a different thing, and no there aren't any common standards, beyond what's forbidden/discouraged from the c++ standard language.
Well, rethinking the standard style guide wording, there actually are established coding style standards like e.g. Misra C++.
You'll need to consider fulfilling these to get into certain business domains. You may think these are silly, and too restrictive, but still the customer wants you to fulfill these style guides.
It's your choice, and you'll need to estimate your extra efforts and costs (for e.g. investing in a static analysis tool that confirms standard compliance), and put that on the customers bill.
Even though I think the given answers are already good i would like to add the following comment:
There is a rather new project C++ Core Guidelines which tries to do what you are looking for (at least I think so). It is still in an ongoing process but IMHO it is already worth to take a look. There are also some nice talks about these guidelines
CppCon 2015: Bjarne Stroustrup “Writing Good C++14”
and
CppCon 2015: Herb Sutter "Writing Good C++14... By Default"
which explains its main purpose quite nicely. They emphasize static code analysis alot and in my opinion they try to push it alot with these guidelines.
But an important information is
FAQ.6: Have these guidelines been approved by the ISO C++ standards
committee? Do they represent the consensus of the committee?
No. These guidelines are outside the standard. They are intended to
serve the standard, and be maintained as current guidelines about how
to use the current Standard C++ effectively. We aim to keep them in
sync with the standard as that is evolved by the committee.
In the end it means, it is just another set of rules in the sense of the other answers.
No.
If there were a single style guide that everybody followed, why would there be multiple style guides?
For what it's worth, I don't follow anyone else's style guide, and in my opinion neither should you.
Your job may require you to follow a certain guide, but then you wouldn't be asking us which to use.
Notice that I refuse to call these style guides "standards".

How should the C++ standard be used

I have this classic question of how should the C++ Standard (I mean the actual official document of the finalized ones) e.g. C++98, C++03 be used to learn and teach C++. My idea is only from the point of view of an average C++ user and not from the point of view of the language lawyers or someone who wishes to be in the Standards committee, compiler writers and so on.
Here are my personal thoughts:
a) It is aweful place to start learning C++. Books like "C++ in a Nutshell", "The C++ programming Language" etc do a very good job on that front while closely aligning with the Standard.
b) One needs to revert to the Standard only when
a compiler gives a behavior which is not consistent with what the common books say or,
a certain behavior is inconsistent across compilers e.g. GCC, VS, Comeau etc. I understand the fact that these compilers could be inconsistent is in very few cases / dark corners of the language e.g. templates/exception handling etc. However one really comes to know about the possible different compiler behaviors only when either one is porting and/or migrating to a different environment or when there is a compiler upgrade e.g.
if a concept is poorly explained / not explained in the books at hand e.g. if it is a really advanced concept
Any thoughts/ideas/recommendation on this?
The C++ language standard would be an absolutely terrible place to start learning the language. It is dense, obtuse, and really long. Often the information you are looking for is spread across seven different clauses or hidden in a half of a sentence in a clause completely unrelated to where you think it should be (or worse, a behavior is specified in the sentence you ignored because you didn't think it was relevant).
It does have its uses, of course. To name a few,
If you think you've found a bug in a compiler, it's often necessary to refer to the standard to make sure you aren't just misunderstanding what the specified behavior is.
If you find behavior that is inconsistent between compilers, it's handy to be able to look up which is correct (or which is more correct), though often you'll need to write workarounds regardless.
If you want to know why things are the way they are, it is often a good reference: you can see how different features of the language are related and understand how they interact. Things aren't always clear, of course, but they often are. There are a lot of condensed examples and notes demonstrating and explaining the normative text.
If you reference the C++ standard in a post on Stack Overflow, you get more a lot more upvotes. :-)
It's very interesting to learn about the language. It's one thing to write code and stumble through getting things to compile and run. It's another thing altogether to go and try to understand the language as a whole and understand why you have to do things a certain way.
The standard should be used to ensure portability of code.
When writing basic c++ code you shouldn't need to refer to the standards, but when using templates or advanced use of the STL, reference to the standard is essential to maintain compatibility with more than one compiler, and forward compatibility with future versions.
I use g++ to compile my C++ programs and there I use the option -std=c++0x (earlier, -std=c++98) to make sure that my code is always standard compliant. If I get any warning or error regarding standard compliance, I research on that to educate myself and fix my code.

C++ coding standard for small group using modern IDEs

We are going to start a new project in our team which consists of less than 10 developers.
We have access to modern IDEs such as VS2010.
The project is extremely dynamic (users' needs change very quick) and cross platform. Therefore, I need a highly readable and very detailed C++ coding standard so new developers can easily change the old codes in future. I also need a not to write list so the code will compile on different OSes (at least windows and linux).
Is there such a standard?
Are coding standards expired already?
Coding standards remain an issue because everyone secretly thinks they can solve all the world's programming problems with a very clever coding standard. And then forcing programmers to follow them. (Pretty much like programming programmers.)
Unfortunately, few coding standards address the issues that matter in a complex project like:
how to cleanly and effectively partition and model a problem
how program partitions should best interact with others
how an explanation of logic ("comment") should be written to explain the code
Instead, most coding standards address trivia like:
indentation and brace style
whether comments should be present or not
mechanical rules about constructing identifiers
placing arbitrary limits on characters in a line, number of parameters, etc., etc.
As for the primary question, I don't know of any good detailed standards other than design and implement code which other engineers would be proud of.
Read C++ Coding Standards. It is not what most people would call a coding standards document, but you probably want to read it. One of the first guides is do not swell the small stuff (do not put too much emphasis on details: focus on rules that affect the semantic not the syntax, as in prefer RAII over raw pointers instead of add braces everywhere, in it's own line and indenting 3 spaces)
As far as coding standard go, in most cases, it's less important what the specific coding standards are, so long as they're firmly in place. Tabs vs. space? Who cares. Pick one and go with it. Curly braces on the same line as the conditional or the next line? Who cares. Pick one and stay consistent.
I personally like the Linux kernel coding standards.
http://www.kernel.org/doc/Documentation/CodingStyle
It is for C, and not C++, but it may be a good place to start on the standards for your project. Unfortunately, I doubt it offers suggestions on a "do not write" list.
I highly recommend the Google style guide, which I haven't stopped using since interning there two years ago. The link above enumerates the rules in detail, along with each rule's justification in terms of pros and cons.
It is indeed highly readable and very detailed, but the important rules (the ones that come up all the time) are few and easy to remember. They have really streamlined my C++ coding by giving consistency to my naming and function argument-passing conventions.
I know you're using an IDE, but emacs users can use their "google.el" file for automatic formatting. There's also a powerful "cpplint" script that runs through a source file, printing out style violations in the same warning format as used by gcc. This lets you quickly fix style violations before checking in a file. If your IDE can parse gcc warnings and jump from warning to warning in a source file, then fixing such violations becomes a snap. Emacs and Eclipse CDT do this, as do other editors/IDEs.

C++ languages extensions

I already read the FAQ, and i think maybe this is a subjective question, but i need to ask.
Does anyine knows what exactly (i mean formally) is a C++ language extensions.
I already saw examples, like nvdia CUDA c ext, Avalon transaction-based c++ ext.
So the point is something like a formal definition or so.
thxs anyway.
A language extension is simply anything that goes beyond what the language specification calls for. Your compiler might add new features, like special "min" and "max" operators. Your compiler might define the behavior of division by zero, which is otherwise undefined, according to the standard. It might provide additional parameters for your main function. It might be the incorporation of another language's features, such as allowing C-style variable-sized arrays in C++. It might be a facility for specifying a function's calling convention.
Using a language extension usually makes your code non-portable because when you take your code to another OS, compiler, or even compiler version, the extension may not be available anymore, or its behavior may be different from what you had originally used.
Please see Extensible programming:
Extensible programming is a term used
in computer science to describe a
style of computer programming that
focuses on mechanisms to extend the
programming language, compiler and
runtime environment.
and more to the point, the Extensible syntax section:
This simply means that the source
language(s) to be compiled must not be
closed, fixed, or static. It must be
possible to add new keywords,
concepts, and structures to the source
language(s).