string-plus-char.c 1.5 KB

123456789101112131415161718192021222324252627282930
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. struct AB{const char *a; const char*b;};
  3. const char *foo(const struct AB *ab) {
  4. 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}}
  5. }
  6. void f(const char *s) {
  7. char *str = 0;
  8. 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}}
  9. 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}}
  10. 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}}
  11. char strArr[] = "foo";
  12. 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}}
  13. char *strArr2[] = {"ac","dc"};
  14. 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}}
  15. struct AB ab;
  16. 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}}
  17. // no-warning
  18. char c = 'c';
  19. str = str + c;
  20. str = c + str;
  21. }