Static Code Analyzer for C++ in Linux [duplicate] - c++

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What open source C++ static analysis tools are available?
Does anybody know of an open source,good static code analyzer for C++ code in Linux ?
The idea is to catch programming errors even before the code goes in to the code review state.
It would be great to have the possibility to add rules the tool.
Does anybody know of such tool?

lint, found here: http://en.wikipedia.org/wiki/Lint_(software)
cppcheck, found here: http://cppcheck.wiki.sourceforge.net/

you can give a try pvs-studio:
http://www.viva64.com/en/pvs-studio/ (1)
also there is (bla-bla-lint):
http://www.gimpel.com/html/index.htm (2)
missed note about linux,
FlexeLint for C/C++ from (2) has linux support,
(1) only for windows, you can check it only if your product crossplatform.

You can also customize GCC (4.6) by using plugins (coded in C) or MELT extensions (MELT is a high-level domain specific language to extend and customize GCC). This approach could be appropriate if you have your own coding rules that you want to check. However, it does take some work.

Take a look at clang's static analizer: http://clang-analyzer.llvm.org/
There are other tools like KLEE based on llvm, might worth a look, too.

Related

Are there commands in Gcc to get the description of a keywords(or functions etc)?

Previosly i used turboc++, but recently shifted to codeblocks and sometimes i also use notepad (i compile code using gcc via command promt, though possible in codeblocks). Now previously, in turbo c++ i used ctrl+F1 to get help for particular function or keywords or headerfiles etc, by keeping the cursor line on the keywords, the help is regarding the description of what the function does, whatever etc. Now in gcc(or in code::blocks) i want to know is it possible to get the help for, lets say for a perticular keyword, using some commands in gcc under command prompt?
(not sure, but i heard it is possible in clang).
What you're looking for is an IDE.
There are many, many choices. I'd strong recommend looking at Eclipse CDT:
http://www.eclipse.org/cdt/
http://www.ibm.com/developerworks/library/os-eclipse-stlcdt/
PS:
The "C:B" referred to above is "Code Blocks". That might also be a good choice for you - check it out, too:
http://www.codeblocks.org/

Is there any software to format source code for C/C++ on Mac? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Objective-C style formatter
I have wrote a program and wonder if there is any software to format the codes the way it should look like a good programmer?
I know I shouldn't rely on it but just for my curiosity and to have this done in a better way because my code it so mess up and I want it look nicer and better.
On mac would be appreciated if not PC would be okay.
If you're using XCode, you can re-indent your files (Editor -> Structure -> Re-Indent), or with the keyboard shortcut: ControlI.
One nice code formatter is astyle. The download link can be found here. And I just checked, they support Mac as well.
There's the command-line program indent, which does not do complete style formatting but does get indentation sorted out for you. indent should come with your Mac (or maybe it comes with Xcode? not sure). See man indent.

Any good recently developed flexible C++ Style checker?

I know this question has been asked here, however it was from 2010 and I was wondering if anybody knows of some recent ones made.
I'm looking into using a style checker to help enforce coding conventions at my current workplace. I see the following few options:
A nice flexible way to enforce difference style conventions exist. Vera++ looked interesting and extendable.
Use/hack Google's cpplint style checker (seems daunting)
get access to the parse tree (preferably the AST) of the current file and perform checks on that.
#3 seems the most flexible and wondering whether anyone knows of a program or way to hook into the AST?
Try xCode with clang and all warning on.
You can also make clang dump the AST.
CppCheck build an AST. And it also allows you to write addons, where you can get access to AST. But as stated above it may wipe necessary information needed to check style. My choice is to customize cpplint.

Is there a way of disabling the old c style casts in c++ [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to find (and replace) all old C-style data type casts in my C++ source code?
I'm currently refactoring some old code and the project I am working on has a policy of only using the new c++ style casts. I'm trying to make sure that I don't miss any but currently the approach I'm taking is quite crude so I'm wondering if there is any way of making the old c style casts not compile in a c++ project? (or at least give a compiler warning if this is not possible)
If you use GCC, add -Wold-style-cast to the command line. That gives warnings, not errors, but you can always add -Werror, which turns warnings (all warnings) into errors.
As for other compilers, it seems no other compiler has such a warning option.
But that doesn't really matter: GCC is Free Software, and available on practically anything that can distinguish between zeros and ones. Just install it alongside your main compiler on your workstation, or into your continuous integration system, and use it for this task only. You will find that having two C++ compilers at hand is very convenient in general.
If installing GCC really isn't an option for you, you might want to take a peek at How to find (and replace) all old C-style data type casts in my C++ source code?, where some alternatives are discussed.
I recommend using this Perl script. Except for unusual conditions like
(void**)&b.ComInterfaceCall
it just appears to work.

What is the tool to check include file that are useless?(c++) [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
Tools to find included headers which are unused?
I would like to check useless header file in c++ files(.h and .cpp)
During developing, There are so many relations between files.
So it cause compile time more longer.
Can you tell me what's the tool that help me.
Thank you.
Have a look at the Dehydra.
From the website:
Dehydra is a lightweight, scriptable, general purpose static analysis tool capable of application-specific analyses of C++ code. In the simplest sense, Dehydra can be thought of as a semantic grep tool.
It should be possible to come up with a script that checks for unused #include files.
I use lint, Verify the link, it does mention unused variables, unreachable statements and many more.