new file mode 100644
@@ -0,0 +1,26 @@
+/* Test -Wstring-plus-char. */
+
+/* { dg-do compile } */
+/* { dg-options "-Wstring-plus-char" } */
+
+typedef __UINT_LEAST16_TYPE__ uint_least16_t;
+
+char *a;
+const char *b;
+char c;
+const char *d;
+uint_least16_t x;
+
+int main(void)
+{
+ d = a + c; /* { dg-warning "does not append" } */
+ d = b + c; /* { dg-warning "does not append" } */
+ d = a + 'a'; /* { dg-warning "does not append" } */
+ d = b + 'a'; /* { dg-warning "does not append" } */
+ d = 'a' + b; /* { dg-warning "does not append" } */
+ d += 'a'; /* { dg-warning "does not append" } */
+ d = a + x; /* { dg-bogus "does not append" } */
+ d = b + x; /* { dg-bogus "does not append" } */
+ d = a + 1u; /* { dg-bogus "does not append" } */
+ d = a + 1; /* { dg-bogus "does not append" } */
+}
new file mode 100644
@@ -0,0 +1,16 @@
+/* Test -Wstring-plus-char for C++ wide char types. */
+
+/* { dg-do compile } */
+/* { dg-options "-Wstring-plus-char" } */
+
+const wchar_t *a, *d;
+wchar_t b;
+int c;
+
+int main(void)
+{
+ d = a + L'a'; /* { dg-warning "does not append" } */
+ d = a + b; /* { dg-warning "does not append" } */
+ d = a + c; /* { dg-bogus "does not append" } */
+ d = a + 1; /* { dg-bogus "does not append" } */
+}
new file mode 100644
@@ -0,0 +1,26 @@
+/* Test -Wstring-plus-char for C++ 2011 unicode char types. */
+
+/* { dg-do compile } */
+/* { dg-options "-std=c++11 -Wstring-plus-char" } */
+
+typedef __UINT_LEAST16_TYPE__ uint_least16_t;
+typedef __UINT_LEAST32_TYPE__ uint_least32_t;
+
+const char16_t *a, *d;
+char16_t b;
+uint_least16_t c;
+const char32_t *e, *h;
+char32_t f;
+uint_least32_t g;
+
+int main(void)
+{
+ d = a + u'a'; /* { dg-warning "does not append" } */
+ d = a + b; /* { dg-warning "does not append" } */
+ d = a + c; /* { dg-bogus "does not append" } */
+ d = a + 1; /* { dg-bogus "does not append" } */
+ h = e + U'a'; /* { dg-warning "does not append" } */
+ h = e + f; /* { dg-warning "does not append" } */
+ h = e + g; /* { dg-bogus "does not append" } */
+ h = e + 1; /* { dg-bogus "does not append" } */
+}
new file mode 100644
@@ -0,0 +1,32 @@
+/* Test -Wstring-plus-char.
+ This is a more realistic test case. */
+
+/* { dg-do compile } */
+/* { dg-options "-Wstring-plus-char" } */
+
+class good_string
+{
+public:
+ good_string(const char *);
+ good_string &operator=(const char *);
+ good_string operator+(char) const;
+ operator const char *(void) const;
+};
+
+/* Someone has forgotten operator+ overload... */
+class bad_string
+{
+public:
+ bad_string(const char *);
+ bad_string &operator=(const char *);
+ operator const char *(void) const;
+};
+
+int main()
+{
+ good_string good = "aa";
+ good = good + 'a'; /* { dg-bogus "does not append" } */
+ bad_string bad = "bb";
+ bad = bad + 'b'; /* { dg-warning "does not append" } */
+ return 0;
+}
--
2.7.1