Integrate Clang Static Analyzer (aka. scan-build) with flycheck to automatically perform on-the-fly static analysis as you code.
This package leverages the configuration of the existing c/c++-clang flycheck
checker, or either
emacs-cquery,
emacs-ccls,
irony-mode or
rtags to provide the appropriate
compiler flags for clang - and so requires zero extra setup. This checker also
automatically chains itself as the next flycheck checker after c/c++-clang,
lsp-ui
flycheck-irony and
flycheck-rtags so that it only runs
when the corresponding previous checker returns without warnings. This avoids
trying to perform the analysis when there are syntactic errors etc.
The preferred way to install flycheck-clang-analyzer is via
MELPA - then you can just M-x package-install RET
flycheck-clang-analyzer RET
To enable then simply add the following to your init file:
(with-eval-after-load 'flycheck
(require 'flycheck-clang-analyzer)
(flycheck-clang-analyzer-setup))We recommend to use use-package to make this automatic:
(use-package flycheck-clang-analyzer
:ensure t
:after flycheck
:config (flycheck-clang-analyzer-setup))If you would like to install the package manually, download or clone it and
place it within Emacs' load-path, then you can require it in your init file
like this:
(require 'flycheck-clang-analyzer)
(flycheck-clang-analyzer-setup)NOTE: This will also require the manual installation of flycheck if you have
not done so already.
This should work with zero configuration, since we try and leverage the configuration of existing clang-based Flycheck checkers.
The only configuration option is flycheck-clang-analyzer-executable which is
the path to the clang executable - this defaults to clang. However if you
need to change this to something else, simply setq it as appropriate before
calling (flycheck-clang-analyzer-setup) - so to set to use clang-3.8
instead of clang:
(setq flycheck-clang-analyzer-executable "clang-3.8")
(flycheck-clang-analyzer-setup)Copyright © 2018 Alex Murray
Distributed under GNU GPL, version 3.
