namespace tidy {
namespace hicpp {
+SignedBitwiseCheck::SignedBitwiseCheck(StringRef Name,
+ ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ IgnorePositiveIntegerLiterals(
+ Options.get("IgnorePositiveIntegerLiterals", false)) {}
+
+void SignedBitwiseCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "IgnorePositiveIntegerLiterals",
+ IgnorePositiveIntegerLiterals);
+}
+
void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
const auto SignedIntegerOperand =
- expr(ignoringImpCasts(hasType(isSignedInteger()))).bind("signed-operand");
+ (IgnorePositiveIntegerLiterals
+ ? expr(ignoringImpCasts(hasType(isSignedInteger())),
+ unless(integerLiteral()))
+ : expr(ignoringImpCasts(hasType(isSignedInteger()))))
+ .bind("signed-operand");
// The standard [bitmask.types] allows some integral types to be implemented
// as signed types. Exclude these types from diagnosing for bitwise or(|) and
/// http://clang.llvm.org/extra/clang-tidy/checks/hicpp-signed-bitwise.html
class SignedBitwiseCheck : public ClangTidyCheck {
public:
- SignedBitwiseCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context) {}
+ SignedBitwiseCheck(StringRef Name, ClangTidyContext *Context);
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ void storeOptions(ClangTidyOptions::OptionMap &Options) override;
+
+private:
+ bool IgnorePositiveIntegerLiterals;
};
} // namespace hicpp
Finds uses of deprecated Googletest APIs with names containing ``case`` and
replaces them with equivalent APIs with ``suite``.
+- Improved :doc:`hicpp-signed-bitwise
+ <clang-tidy/checks/hicpp-signed-bitwise>` check.
+
+ The check now supports the ``IgnorePositiveIntegerLiterals`` option.
+
- New :doc:`linuxkernel-must-use-errs
<clang-tidy/checks/linuxkernel-must-use-errs>` check.
undefined or implementation defined behaviour.
The according rule is defined in the `High Integrity C++ Standard, Section 5.6.1 <http://www.codingstandard.com/section/5-6-shift-operators/>`_.
+
+Options
+-------
+
+.. option:: IgnorePositiveIntegerLiterals
+
+ If this option is set to `true`, the check will not warn on bitwise operations with positive integer literals, e.g. `~0`, `2 << 1`, etc.
+ Default value is `false`.