0

I have one issue with Cppcheck during enable it in Vim, for normal code it works fine but normally I have typedef and some functions which may not known by Cppcheck. For individual check, I have no problem because I can write library and rules for Cppcheck, for example mycppcheck.cfg file:

<?xml version="1.0"?>

<def>
    <!-- 2015-Oct-23 requested by Chen How -->
    <function name="Printf"><noreturn>false</noreturn></function>
</def>

<def>
    <podtype name="Int8" sign="s" size="1"/>
    <podtype name="UInt8" sign="u" size="1"/>
    <podtype name="Int16" sign="s" size="2"/>
    <podtype name="UInt16" sign="u" size="2"/>
    <podtype name="Int32" sign="s" size="4"/>
    <podtype name="UInt32" sign="u" size="4"/>
</def>

<def>
    <memory>
    <alloc>my_malloc</alloc>
    <dealloc>my_free</dealloc>
    </memory>
</def>

When I use Cppcheck, I do the following command:

$ cppcheck --library=mycppcheck.cfg

When I use Cppcheck in Vim, how can I tell Cppcheck, for the current file, which library it should use? Without a library, Cppcheck can't identify the correct risk.

I use syntastic as the plug-in for Vim. Is there another way to enable the Cppcheck facility without this plug-in?

I also checked the topic Which error format should be used for Vim and Cppcheck?. I think it can work for me, but I did not find the library define in this. Regarding the above topic, my first guess is changing:

set makeprg=cppcheck\ --enable=all\ %

to

set makeprg=cppcheck\ --library=mycppcheck.cfg --enable=all\ %

More findings @ syntastic

4.8. How can I pass additional arguments to a checker?

A. Almost all syntax checkers use the makeprgBuild() function. Those checkers that do can be configured using global variables. The general form of the global arguments variables is syntastic___args.

So, if you wanted to pass --my --args --here to the Ruby mri checker, you would add this line to your vimrc file:

let g:syntastic_ruby_mri_args = "--my --args --here"

See :help syntastic-checker-options for more information.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
How Chen
  • 1,340
  • 2
  • 17
  • 37
  • You'll need to tell us what plugin you use to invoke cppcheck. – Benjamin Bannier Oct 26 '15 at 11:59
  • @BenjaminBannier, OK, I will add into my question, I use `syntastic` – How Chen Oct 26 '15 at 12:06
  • If you mean that the `mycppcheck.cfg` file to select depends on the current project (or even the current file) to check, then you can use one of the numerous [local_vimrc](https://github.com/LucHermitte/local_vimrc) plugin. – Luc Hermitte Oct 26 '15 at 12:50
  • @LucHermitte, `mycppcheck.cfg` is for cppcheck not for vim I think – How Chen Oct 27 '15 at 01:15
  • Of course. But you want to use it from vim. Now the question: is the choice of the cppcheck config file dependent on the files you want to check, and is your question about how to fetch the exact filename and inject it to cppcheck call ? – Luc Hermitte Oct 27 '15 at 07:25

0 Answers0