summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre@debian.org>2018-12-13 16:06:23 +0000
committerSylvestre Ledru <sylvestre@debian.org>2018-12-13 16:06:23 +0000
commit8523c085e7ed663352dfd5f96787691056f6a182 (patch)
treeaa24484e8eea77da7d898f38f365306fb0a83146 /clang/test
parent4974d75d7cd6c05788c839cc05098e417c15c74c (diff)
downloadbcm5719-llvm-8523c085e7ed663352dfd5f96787691056f6a182.tar.gz
bcm5719-llvm-8523c085e7ed663352dfd5f96787691056f6a182.zip
Make -Wstring-plus-int warns even if when the result is not out of bounds
Summary: Patch by Arnaud Bienner Reviewers: sylvestre.ledru, thakis Reviewed By: thakis Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55382 llvm-svn: 349054
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaCXX/string-plus-int.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/clang/test/SemaCXX/string-plus-int.cpp b/clang/test/SemaCXX/string-plus-int.cpp
index fe9c7194969..448fb49fb49 100644
--- a/clang/test/SemaCXX/string-plus-int.cpp
+++ b/clang/test/SemaCXX/string-plus-int.cpp
@@ -31,37 +31,36 @@ void f(int index) {
consume("foo" + 5); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
consume("foo" + index); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
consume("foo" + kMyEnum); // expected-warning {{adding 'MyEnum' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
+ consume("foo" + kMySmallEnum); // expected-warning {{adding 'MyEnum' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
consume(5 + "foo"); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
consume(index + "foo"); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
consume(kMyEnum + "foo"); // expected-warning {{adding 'MyEnum' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
+ consume(kMySmallEnum + "foo"); // expected-warning {{adding 'MyEnum' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
// FIXME: suggest replacing with "foo"[5]
consumeChar(*("foo" + 5)); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
consumeChar(*(5 + "foo")); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
consume(L"foo" + 5); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
+ consume(L"foo" + 2); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
+
+ consume("foo" + 3); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
+ consume("foo" + 4); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
+ consume("\pfoo" + 4); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
+
+ #define A "foo"
+ #define B "bar"
+ consume(A B + sizeof(A) - 1); // expected-warning {{to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
// Should not warn.
consume(&("foo"[3]));
consume(&("foo"[index]));
consume(&("foo"[kMyEnum]));
- consume("foo" + kMySmallEnum);
- consume(kMySmallEnum + "foo");
- consume(L"foo" + 2);
-
- consume("foo" + 3); // Points at the \0
- consume("foo" + 4); // Points 1 past the \0, which is legal too.
- consume("\pfoo" + 4); // Pascal strings don't have a trailing \0, but they
- // have a leading length byte, so this is fine too.
consume("foo" + kMyOperatorOverloadedEnum);
consume(kMyOperatorOverloadedEnum + "foo");
-
- #define A "foo"
- #define B "bar"
- consume(A B + sizeof(A) - 1);
}
template <typename T>
OpenPOWER on IntegriCloud