Skip to content

Commit

Permalink
Add option for additional definitions for Clang [#207]
Browse files Browse the repository at this point in the history
  • Loading branch information
swsnr committed Sep 14, 2013
1 parent 8314424 commit 228f31b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
7 changes: 7 additions & 0 deletions doc/flycheck.texi
Expand Up @@ -588,6 +588,10 @@ describe-variable} on the variable name for detailed help):
Include search path for @code{c/c++-clang}.
@end defopt

@defopt flycheck-clang-definitions
Additional preprocessor definitions for @code{c/c++-clang}.
@end defopt

@defopt flycheck-clang-language-standard
The language standard for @code{c/c++-clang}.
@end defopt
Expand Down Expand Up @@ -2808,6 +2812,9 @@ completion systems for @code{flycheck-select-checker} at @kbd{C-c ! s}
@item
@ghissue{207, Add @code{flycheck-clang-language-standard} to choose the
language standard for C/C++ syntax checking}
@item
@ghissue{207, Add @code{flycheck-clang-definitions} to set additional
definitions for C/C++ syntax checking}
@end itemize
@end itemize
Expand Down
11 changes: 11 additions & 0 deletions flycheck.el
Expand Up @@ -3224,6 +3224,16 @@ Relative paths are relative to the file being checked."
:safe #'flycheck-string-list-p
:package-version '(flycheck . "0.14"))

(flycheck-def-option-var flycheck-clang-definitions nil c/c++-clang
"Additional preprocessor definitions for Clang.
The value of this variable is a list of strings, where each
string is an additional definition to pass to Clang, via the `-D'
option."
:type '(repeat (string :tag "Definition"))
:safe #'flycheck-string-list-p
:package-version '(flycheck . "0.15"))

(flycheck-def-option-var flycheck-clang-language-standard nil c/c++-clang
"The language standard to use in Clang.
Expand Down Expand Up @@ -3265,6 +3275,7 @@ See URL `http://clang.llvm.org/'."
; warning group
(option "-std=" flycheck-clang-language-standard)
(option-list "-W" flycheck-clang-warnings s-prepend)
(option-list "-D" flycheck-clang-definitions s-prepend)
(option-list "-I" flycheck-clang-include-path)
"-x" (eval
(cl-case major-mode
Expand Down
17 changes: 13 additions & 4 deletions test/builtin-checkers-test.el
Expand Up @@ -105,17 +105,26 @@
:expected-result (flycheck-testsuite-fail-unless-checker 'c/c++-clang)
(flycheck-testsuite-should-syntax-check
"checkers/c_c++-clang-error.cpp" 'c++-mode nil
'(5 18 "implicit instantiation of undefined template 'test<false>'" error)
'(6 17 "'nullptr' is a keyword in C++11" warning)
'(6 17 "use of undeclared identifier 'nullptr'" error)))
'(6 17 "implicit instantiation of undefined template 'test<false>'" error)
'(8 16 "'nullptr' is a keyword in C++11" warning)
'(8 16 "use of undeclared identifier 'nullptr'" error)))

(ert-deftest checker-c/c++-clang-error-language-standard ()
:expected-result (flycheck-testsuite-fail-unless-checker 'c/c++-clang)
(flycheck-testsuite-with-hook c++-mode-hook
(setq flycheck-clang-language-standard "c++11")
(flycheck-testsuite-should-syntax-check
"checkers/c_c++-clang-error.cpp" 'c++-mode nil
'(5 18 "implicit instantiation of undefined template 'test<false>'" error))))
'(6 17 "implicit instantiation of undefined template 'test<false>'" error))))

(ert-deftest checker-c/c++-clang-error-definitions ()
:expected-result (flycheck-testsuite-fail-unless-checker 'c/c++-clang)
(flycheck-testsuite-with-hook c++-mode-hook
(setq flycheck-clang-definitions '("FOO" "BAR"))
(flycheck-testsuite-should-syntax-check
"checkers/c_c++-clang-error.cpp" 'c++-mode nil
'(8 16 "'nullptr' is a keyword in C++11" warning)
'(8 16 "use of undeclared identifier 'nullptr'" error))))

(ert-deftest checker-c/c++-cppcheck-error ()
:expected-result (flycheck-testsuite-fail-unless-checker 'c/c++-cppcheck)
Expand Down
8 changes: 5 additions & 3 deletions test/resources/checkers/c_c++-clang-error.cpp
Expand Up @@ -2,7 +2,9 @@ template<bool> struct test;
template<> struct test<true> {};

int main(void) {
test<false> t;
int *foo = nullptr;
return 0;
#if !(defined(FOO) && defined(BAR))
test<false> t;
#endif
int *foo = nullptr;
return 0;
}

0 comments on commit 228f31b

Please sign in to comment.