annotate clang/test/Sema/string-plus-char.c @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 struct AB{const char *a; const char*b;};
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 const char *foo(const struct AB *ab) {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
7 }
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 void f(const char *s) {
anatofuz
parents:
diff changeset
10 char *str = 0;
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 char strArr[] = "foo";
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
19 char *strArr2[] = {"ac","dc"};
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 struct AB ab;
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 // no-warning
anatofuz
parents:
diff changeset
27 char c = 'c';
anatofuz
parents:
diff changeset
28 str = str + c;
anatofuz
parents:
diff changeset
29 str = c + str;
anatofuz
parents:
diff changeset
30 }