diff options
author | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2014-12-15 20:22:33 +0000 |
---|---|---|
committer | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2014-12-15 20:22:33 +0000 |
commit | 368590094a96d645cf6ac147f49e7ca4ca97a8f8 (patch) | |
tree | 688702a1adeca37c837b20d9aa6b5bfbf78b8442 /clang/test | |
parent | 26f884aedfe37b53eafcb078380b941b2a12aa2a (diff) | |
download | bcm5719-llvm-368590094a96d645cf6ac147f49e7ca4ca97a8f8.tar.gz bcm5719-llvm-368590094a96d645cf6ac147f49e7ca4ca97a8f8.zip |
Sema: Cleanup and improve string-plus-char checking.
Patch by Anders Rönnholm
llvm-svn: 224268
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Sema/string-plus-char.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/test/Sema/string-plus-char.c b/clang/test/Sema/string-plus-char.c index 322e8f5962b..66c1182eb04 100644 --- a/clang/test/Sema/string-plus-char.c +++ b/clang/test/Sema/string-plus-char.c @@ -1,5 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +struct AB{const char *a; const char*b;}; + +const char *foo(const struct AB *ab) { + return ab->a + 'b'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} +} + void f(const char *s) { char *str = 0; char *str2 = str + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} @@ -8,6 +14,15 @@ void f(const char *s) { str = 'c' + str;// expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} + char strArr[] = "foo"; + str = strArr + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} + char *strArr2[] = {"ac","dc"}; + str = strArr2[0] + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} + + + struct AB ab; + constStr = foo(&ab) + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} + // no-warning char c = 'c'; str = str + c; |