diff options
author | Jonas Toth <jonas.toth@gmail.com> | 2017-10-03 16:25:01 +0000 |
---|---|---|
committer | Jonas Toth <jonas.toth@gmail.com> | 2017-10-03 16:25:01 +0000 |
commit | c1f906c134feab3d5602e869f0983b8b35f18394 (patch) | |
tree | e6cd30809a59d8ce78d392e3f8a0f6b5550e3be4 | |
parent | ea523ddb1b14ee8d008859bd6878474827315b5a (diff) | |
download | bcm5719-llvm-c1f906c134feab3d5602e869f0983b8b35f18394.tar.gz bcm5719-llvm-c1f906c134feab3d5602e869f0983b8b35f18394.zip |
[clang-tidy] Fix bug 34747, streaming operators and hicpp-signed-bitwise
The bug happened with stream operations, that were not recognized in all cases.
Even there were already existing test for streaming classes, they did not catch this bug.
Adding the isolated example to the existing tests did not trigger the bug.
Therefore i created a new isolated file that did expose the bug indeed.
Differential: https://reviews.llvm.org/D38399
reviewed by aaron.ballman
llvm-svn: 314808
-rw-r--r-- | clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp | 4 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp | 21 |
2 files changed, 24 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp index acd7216a68a..08aed6571b8 100644 --- a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp +++ b/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp @@ -27,7 +27,9 @@ void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) { binaryOperator(allOf(anyOf(hasOperatorName("|"), hasOperatorName("&"), hasOperatorName("^"), hasOperatorName("<<"), hasOperatorName(">>")), - hasEitherOperand(SignedIntegerOperand))) + hasEitherOperand(SignedIntegerOperand), + hasLHS(hasType(isInteger())), + hasRHS(hasType(isInteger())))) .bind("binary_signed"), this); diff --git a/clang-tools-extra/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp b/clang-tools-extra/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp new file mode 100644 index 00000000000..bf93566afbc --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp @@ -0,0 +1,21 @@ +// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- -- -std=c++11 | count 0 + +// Note: this test expects no diagnostics, but FileCheck cannot handle that, +// hence the use of | count 0. + +template <typename C> +struct OutputStream { + OutputStream &operator<<(C); +}; + +template <typename C> +struct foo { + typedef OutputStream<C> stream_type; + foo(stream_type &o) { + o << 'x'; // warning occured here, fixed now + } +}; + +void bar(OutputStream<signed char> &o) { + foo<signed char> f(o); +} |