1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
2 | |
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 | |
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 | |
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 | |
26 | // no-warning |
27 | char c = 'c'; |
28 | str = str + c; |
29 | str = c + str; |
30 | } |
31 | |