[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / SemaCXX / string-plus-int.cpp
blob448fb49fb49f08ad2d5c8b0632cc67f597fe420f
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-array-bounds %s -fpascal-strings
2 // RUN: %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2>&1 -Wno-array-bounds -fpascal-strings | FileCheck %s
4 void consume(const char* c) {}
5 void consume(const unsigned char* c) {}
6 void consume(const wchar_t* c) {}
7 void consumeChar(char c) {}
9 enum MyEnum {
10 kMySmallEnum = 1,
11 kMyEnum = 5
14 enum OperatorOverloadEnum {
15 kMyOperatorOverloadedEnum = 5
18 const char* operator+(const char* c, OperatorOverloadEnum e) {
19 return "yo";
22 const char* operator+(OperatorOverloadEnum e, const char* c) {
23 return "yo";
26 void f(int index) {
27 // Should warn.
28 // CHECK: fix-it:"{{.*}}":{31:11-31:11}:"&"
29 // CHECK: fix-it:"{{.*}}":{31:17-31:18}:"["
30 // CHECK: fix-it:"{{.*}}":{31:20-31:20}:"]"
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}}
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}}
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}}
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}}
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}}
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}}
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}}
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}}
41 // FIXME: suggest replacing with "foo"[5]
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}}
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}}
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}}
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}}
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}}
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}}
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}}
52 #define A "foo"
53 #define B "bar"
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}}
56 // Should not warn.
57 consume(&("foo"[3]));
58 consume(&("foo"[index]));
59 consume(&("foo"[kMyEnum]));
62 consume("foo" + kMyOperatorOverloadedEnum);
63 consume(kMyOperatorOverloadedEnum + "foo");
66 template <typename T>
67 void PR21848() {
68 (void)(sizeof(T) + ""); // expected-warning {{to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
70 template void PR21848<int>(); // expected-note {{in instantiation of function template specialization 'PR21848<int>' requested here}}