blob: 66c1182eb0463e987c8b5db767186eb6b381c979 [file] [log] [blame]
Jordan Rose55659412013-10-25 16:52:00 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
Daniel Marjamaki36859002014-12-15 20:22:33 +00003struct AB{const char *a; const char*b;};
4
5const 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 Rose55659412013-10-25 16:52:00 +00009void 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 Marjamaki36859002014-12-15 20:22:33 +000017 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 Rose55659412013-10-25 16:52:00 +000026 // no-warning
27 char c = 'c';
28 str = str + c;
29 str = c + str;
30}