annotate clang/test/SemaCXX/string-plus-int.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +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 -Wno-array-bounds %s -fpascal-strings
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2>&1 -Wno-array-bounds -fpascal-strings | FileCheck %s
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 void consume(const char* c) {}
anatofuz
parents:
diff changeset
5 void consume(const unsigned char* c) {}
anatofuz
parents:
diff changeset
6 void consume(const wchar_t* c) {}
anatofuz
parents:
diff changeset
7 void consumeChar(char c) {}
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 enum MyEnum {
anatofuz
parents:
diff changeset
10 kMySmallEnum = 1,
anatofuz
parents:
diff changeset
11 kMyEnum = 5
anatofuz
parents:
diff changeset
12 };
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 enum OperatorOverloadEnum {
anatofuz
parents:
diff changeset
15 kMyOperatorOverloadedEnum = 5
anatofuz
parents:
diff changeset
16 };
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 const char* operator+(const char* c, OperatorOverloadEnum e) {
anatofuz
parents:
diff changeset
19 return "yo";
anatofuz
parents:
diff changeset
20 }
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 const char* operator+(OperatorOverloadEnum e, const char* c) {
anatofuz
parents:
diff changeset
23 return "yo";
anatofuz
parents:
diff changeset
24 }
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 void f(int index) {
anatofuz
parents:
diff changeset
27 // Should warn.
anatofuz
parents:
diff changeset
28 // CHECK: fix-it:"{{.*}}":{31:11-31:11}:"&"
anatofuz
parents:
diff changeset
29 // CHECK: fix-it:"{{.*}}":{31:17-31:18}:"["
anatofuz
parents:
diff changeset
30 // CHECK: fix-it:"{{.*}}":{31:20-31:20}:"]"
anatofuz
parents:
diff changeset
31 consume("foo" + 5); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
32 consume("foo" + index); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
33 consume("foo" + kMyEnum); // expected-warning {{adding 'MyEnum' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
34 consume("foo" + kMySmallEnum); // expected-warning {{adding 'MyEnum' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 consume(5 + "foo"); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
37 consume(index + "foo"); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
38 consume(kMyEnum + "foo"); // expected-warning {{adding 'MyEnum' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
39 consume(kMySmallEnum + "foo"); // expected-warning {{adding 'MyEnum' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 // FIXME: suggest replacing with "foo"[5]
anatofuz
parents:
diff changeset
42 consumeChar(*("foo" + 5)); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
43 consumeChar(*(5 + "foo")); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 consume(L"foo" + 5); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
46 consume(L"foo" + 2); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 consume("foo" + 3); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
49 consume("foo" + 4); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
50 consume("\pfoo" + 4); // expected-warning {{adding 'int' to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 #define A "foo"
anatofuz
parents:
diff changeset
53 #define B "bar"
anatofuz
parents:
diff changeset
54 consume(A B + sizeof(A) - 1); // expected-warning {{to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 // Should not warn.
anatofuz
parents:
diff changeset
57 consume(&("foo"[3]));
anatofuz
parents:
diff changeset
58 consume(&("foo"[index]));
anatofuz
parents:
diff changeset
59 consume(&("foo"[kMyEnum]));
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 consume("foo" + kMyOperatorOverloadedEnum);
anatofuz
parents:
diff changeset
63 consume(kMyOperatorOverloadedEnum + "foo");
anatofuz
parents:
diff changeset
64 }
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 template <typename T>
anatofuz
parents:
diff changeset
67 void PR21848() {
anatofuz
parents:
diff changeset
68 (void)(sizeof(T) + ""); // expected-warning {{to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
anatofuz
parents:
diff changeset
69 }
anatofuz
parents:
diff changeset
70 template void PR21848<int>(); // expected-note {{in instantiation of function template specialization 'PR21848<int>' requested here}}