blob: 00a2c4550dc092e45176bf37021815824dc8b969 [file] [log] [blame]
Jordan Rose02debf62013-10-25 16:52:00 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
2
3class A {
4public:
5 A(): str() { }
6 A(const char *p) { }
7 A(char *p) : str(p + 'a') { } // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}}
8 A& operator+(const char *p) { return *this; }
9 A& operator+(char ch) { return *this; }
10 char * str;
11};
12
13void f(const char *s) {
14 A a = s + 'a'; // // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}}
15 a = a + s + 'b'; // no-warning
16
17 char *str = 0;
18 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}}
19
20 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}}
21
22 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}}
23
24 wchar_t *wstr;
25 wstr = wstr + L'c'; // expected-warning {{adding 'wchar_t' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}}
26 str2 = str + u'a'; // expected-warning {{adding 'char16_t' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}}
27
28 // no-warning
29 char c = 'c';
30 str = str + c;
31 str = c + str;
32}