Skip to content

Commit

Permalink
Add option to disable RTTI in Clang [#207]
Browse files Browse the repository at this point in the history
  • Loading branch information
swsnr committed Sep 15, 2013
1 parent 0534577 commit 2347c6b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/flycheck.texi
Expand Up @@ -600,6 +600,10 @@ Additional preprocessor definitions for @code{c/c++-clang}.
The language standard for @code{c/c++-clang}.
@end defopt

@defopt flycheck-clang-no-rtti
Whether to disable RTTI in @code{c/c++-clang}.
@end defopt

@defopt flycheck-clang-warnings
Additional warnings to enable in @code{c/c++-clang}.
@end defopt
Expand Down Expand Up @@ -1144,6 +1148,11 @@ string. If omitted, it defaults to @code{list}, so by default,
list before substitution. Items for which the filter returns nil are
dropped. @xref{Option filters}, for a list of built-in option filters.
@item (option-flag @var{option} @var{variable})
This cell is substituted with @var{option}, if the value of
@var{variable} is non-nil. Otherwise it is simply dropped from the
argument list.
@item (eval @var{form})
This cell is substituted with a result of evaluating @var{form}.
@var{form} must either return a string or a list of strings, or
Expand Down Expand Up @@ -2819,6 +2828,12 @@ language standard for C/C++ syntax checking}
@item
@ghissue{207, Add @code{flycheck-clang-definitions} to set additional
definitions for C/C++ syntax checking}
@item
@ghissue{207, Add @code{flycheck-clang-no-rtti} to disable RTTI for
C/C++ syntax checking}
@item
Add new option cell @code{option-flag} for boolean flags in syntax
checker commands
@end itemize
@end itemize
Expand Down
19 changes: 19 additions & 0 deletions flycheck.el
Expand Up @@ -1295,6 +1295,9 @@ error if not."
(`(,(or `option `option-list) ,option-name ,option-var)
(and (stringp option-name)
(symbolp option-var)))
(`(option-flag ,option-name ,option-var)
(and (stringp option-name)
(symbolp option-var)))
(`(,(or `option `option-list) ,option-name ,option-var ,prepender-or-filter)
(and (stringp option-name)
(-all? #'symbolp (list option-var prepender-or-filter))))
Expand Down Expand Up @@ -1675,6 +1678,10 @@ STRING
return a list `(OPTION ITEM1 OPTION ITEM2 ...)'. Otherwise
return nil.
`(option-flag OPTION VARIABLE)'
Retrieve the value of VARIABLE and return OPTION, if the
value is non-nil. Otherwise return nil.
`(eval FORM)
Return the result of evaluating FORM in the buffer to be
checked. FORM must either return a string or a list of
Expand Down Expand Up @@ -1732,6 +1739,9 @@ are substituted within the body of cells!"
(error "Value %S of %S for option %S is not a list of strings"
value variable option-name))
(flycheck-prepend-with-option option-name value prepend-fn)))
(`(option-flag ,option-name ,variable)
(when (symbol-value variable)
option-name))
(`(eval ,form)
(let ((result (eval form)))
(if (or (null result)
Expand Down Expand Up @@ -3245,6 +3255,14 @@ pass the language standard via the `-std' option."
:safe #'stringp
:package-version '(flycheck . "0.15"))

(flycheck-def-option-var flycheck-clang-no-rtti nil c/c++-clang
"Whether to disable RTTI in Clang.
When non-nil, disable RTTI for syntax checks, via `-fno-rtti'."
:type 'boolean
:safe #'booleanp
:package-version '(flycheck . "0.15"))

(flycheck-def-option-var flycheck-clang-warnings '("all" "extra") c/c++-clang
"A list of additional warnings to enable in Clang.
Expand Down Expand Up @@ -3274,6 +3292,7 @@ See URL `http://clang.llvm.org/'."
"-fno-diagnostics-show-option" ; Do not show the corresponding
; warning group
(option "-std=" flycheck-clang-language-standard)
(option-flag "-fno-rtti" flycheck-clang-no-rtti)
(option-list "-W" flycheck-clang-warnings s-prepend)
(option-list "-D" flycheck-clang-definitions s-prepend)
(option-list "-I" flycheck-clang-include-path)
Expand Down
9 changes: 9 additions & 0 deletions test/builtin-checkers-test.el
Expand Up @@ -126,6 +126,15 @@
'(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-no-rtti ()
:expected-result (flycheck-testsuite-fail-unless-checker 'c/c++-clang)
(flycheck-testsuite-with-hook c++-mode-hook
(setq flycheck-clang-no-rtti t)
;; Clang doesn't throw errors for RTTI operators :|, so we basically just
;; test that the option flag doesn't cause any issues
(flycheck-testsuite-should-syntax-check
"checkers/c_c++-clang-error-rtti.cpp" 'c++-mode nil)))

(ert-deftest checker-c/c++-cppcheck-error ()
:expected-result (flycheck-testsuite-fail-unless-checker 'c/c++-cppcheck)
(flycheck-testsuite-should-syntax-check
Expand Down
26 changes: 26 additions & 0 deletions test/checker-api-test.el
Expand Up @@ -139,6 +139,19 @@
'(option-list "-I" flycheck-test-option-var nil number-to-string) 'emacs-lisp)
:type 'wrong-type-argument)))

(ert-deftest flycheck-substitute-argument-option-flag ()
(let ((flycheck-test-option-var nil))
(should-not (flycheck-substitute-argument
'(option-flag "--foo" flycheck-test-option-var) 'emacs-lisp)))
(let ((flycheck-test-option-var t))
(should (equal (flycheck-substitute-argument
'(option-flag "--foo" flycheck-test-option-var) 'emacs-lisp)
"--foo")))
(let ((flycheck-test-option-var (list "bar")))
(should (equal (flycheck-substitute-argument
'(option-flag "--foo" flycheck-test-option-var) 'emacs-lisp)
"--foo"))))

(ert-deftest flycheck-substitute-argument-eval ()
(let ((flycheck-test-option-var '("Hello " "World")))
(should (equal (flycheck-substitute-argument '(eval flycheck-test-option-var) 'emacs-lisp)
Expand Down Expand Up @@ -249,6 +262,19 @@
'(option-list "-I" flycheck-test-option-var nil number-to-string) 'emacs-lisp)
:type 'wrong-type-argument)))

(ert-deftest flycheck-substitute-shell-argument-option-flag ()
(let ((flycheck-test-option-var nil))
(should (s-blank? (flycheck-substitute-shell-argument
'(option-flag "--foo" flycheck-test-option-var) 'emacs-lisp))))
(let ((flycheck-test-option-var t))
(should (equal (flycheck-substitute-shell-argument
'(option-flag "--foo" flycheck-test-option-var) 'emacs-lisp)
"--foo")))
(let ((flycheck-test-option-var (list "bar")))
(should (equal (flycheck-substitute-shell-argument
'(option-flag "--foo" flycheck-test-option-var) 'emacs-lisp)
"--foo"))))

(ert-deftest flycheck-substitute-shell-argument-eval ()
(mocker-let
((flycheck-substitute-argument
Expand Down
14 changes: 14 additions & 0 deletions test/resources/checkers/c_c++-clang-error-rtti.cpp
@@ -0,0 +1,14 @@
#include <iostream>

using namespace std;

class Base {};
class Derived : public Base {};

int main()
{
Derived *d = new Derived;
Base *b = dynamic_cast<Base*>(d);
cout << b;
return 0;
}

0 comments on commit 2347c6b

Please sign in to comment.