summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp4
-rw-r--r--clang-tools-extra/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp21
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);
+}
OpenPOWER on IntegriCloud