Jordan Rose | 5565941 | 2013-10-25 16:52:00 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | |
Daniel Marjamaki | 3685900 | 2014-12-15 20:22:33 +0000 | [diff] [blame] | 3 | struct AB{const char *a; const char*b;}; |
| 4 | |
| 5 | const char *foo(const struct AB *ab) { |
| 6 | 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}} |
| 7 | } |
| 8 | |
Jordan Rose | 5565941 | 2013-10-25 16:52:00 +0000 | [diff] [blame] | 9 | void f(const char *s) { |
| 10 | char *str = 0; |
| 11 | 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}} |
| 12 | |
| 13 | const char *constStr = s + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} |
| 14 | |
| 15 | 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}} |
| 16 | |
Daniel Marjamaki | 3685900 | 2014-12-15 20:22:33 +0000 | [diff] [blame] | 17 | char strArr[] = "foo"; |
| 18 | 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}} |
| 19 | char *strArr2[] = {"ac","dc"}; |
| 20 | 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}} |
| 21 | |
| 22 | |
| 23 | struct AB ab; |
| 24 | 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}} |
| 25 | |
Jordan Rose | 5565941 | 2013-10-25 16:52:00 +0000 | [diff] [blame] | 26 | // no-warning |
| 27 | char c = 'c'; |
| 28 | str = str + c; |
| 29 | str = c + str; |
| 30 | } |