[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
This commit is contained in:
Jonas Toth 2017-10-03 16:25:01 +00:00
parent ea523ddb1b
commit c1f906c134
2 changed files with 24 additions and 1 deletions

View File

@ -27,7 +27,9 @@ void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
binaryOperator(allOf(anyOf(hasOperatorName("|"), hasOperatorName("&"), binaryOperator(allOf(anyOf(hasOperatorName("|"), hasOperatorName("&"),
hasOperatorName("^"), hasOperatorName("<<"), hasOperatorName("^"), hasOperatorName("<<"),
hasOperatorName(">>")), hasOperatorName(">>")),
hasEitherOperand(SignedIntegerOperand))) hasEitherOperand(SignedIntegerOperand),
hasLHS(hasType(isInteger())),
hasRHS(hasType(isInteger()))))
.bind("binary_signed"), .bind("binary_signed"),
this); this);

View File

@ -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);
}