[clang-tools-extra] r314808 - [clang-tidy] Fix bug 34747, streaming operators and hicpp-signed-bitwise
Jonas Toth via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 3 09:25:01 PDT 2017
Author: jonastoth
Date: Tue Oct 3 09:25:01 2017
New Revision: 314808
URL: http://llvm.org/viewvc/llvm-project?rev=314808&view=rev
Log:
[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
Added:
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
Modified: clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp?rev=314808&r1=314807&r2=314808&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp Tue Oct 3 09:25:01 2017
@@ -27,7 +27,9 @@ void SignedBitwiseCheck::registerMatcher
binaryOperator(allOf(anyOf(hasOperatorName("|"), hasOperatorName("&"),
hasOperatorName("^"), hasOperatorName("<<"),
hasOperatorName(">>")),
- hasEitherOperand(SignedIntegerOperand)))
+ hasEitherOperand(SignedIntegerOperand),
+ hasLHS(hasType(isInteger())),
+ hasRHS(hasType(isInteger()))))
.bind("binary_signed"),
this);
Added: clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp?rev=314808&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp Tue Oct 3 09:25:01 2017
@@ -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);
+}
More information about the cfe-commits
mailing list