xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/string-plus-char.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc struct AB{const char *a; const char*b;};
4*0a6a1f1dSLionel Sambuc 
foo(const struct AB * ab)5*0a6a1f1dSLionel Sambuc const char *foo(const struct AB *ab) {
6*0a6a1f1dSLionel Sambuc   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*0a6a1f1dSLionel Sambuc }
8*0a6a1f1dSLionel Sambuc 
f(const char * s)9f4a2713aSLionel Sambuc void f(const char *s) {
10f4a2713aSLionel Sambuc   char *str = 0;
11f4a2713aSLionel Sambuc   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}}
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc   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}}
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc   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}}
16f4a2713aSLionel Sambuc 
17*0a6a1f1dSLionel Sambuc   char strArr[] = "foo";
18*0a6a1f1dSLionel Sambuc   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*0a6a1f1dSLionel Sambuc   char *strArr2[] = {"ac","dc"};
20*0a6a1f1dSLionel Sambuc   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*0a6a1f1dSLionel Sambuc 
22*0a6a1f1dSLionel Sambuc 
23*0a6a1f1dSLionel Sambuc   struct AB ab;
24*0a6a1f1dSLionel Sambuc   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*0a6a1f1dSLionel Sambuc 
26f4a2713aSLionel Sambuc   // no-warning
27f4a2713aSLionel Sambuc   char c = 'c';
28f4a2713aSLionel Sambuc   str = str + c;
29f4a2713aSLionel Sambuc   str = c + str;
30f4a2713aSLionel Sambuc }
31