From: Xi Ruoyao <ryxi@stu.xidian.edu.cn>
To: gcc-patches@gcc.gnu.org
Cc: ryxi@stu.xidian.edu.cn
Subject: [PATCH 5/6] New warnings -Wstring-plus-{char, int} (PR c++/62181)
Date: Mon, 12 Jun 2017 01:39:00 -0000 [thread overview]
Message-ID: <1497231545.27153.15.camel@stu.xidian.edu.cn> (raw)
In-Reply-To: <1497230800.27153.4.camel@stu.xidian.edu.cn>
[-- Attachment #1: Type: text/plain, Size: 1098 bytes --]
This patch adds tests for -Wstring-plus-char.
gcc/ChangeLog:
2017-06-12  Xi Ruoyao  <ryxi@stu.xidian.edu.cn>
* testsuite/c-c++-common/Wstring-plus-char.c: New test.
* testsuite/g++.dg/Wstring-plus-char-1.C: Ditto.
* testsuite/g++.dg/Wstring-plus-char-2.C: Ditto.
* testsuite/g++.dg/Wstring-plus-char-3.C: Ditto.
---
 gcc/testsuite/c-c++-common/Wstring-plus-char.c | 26 +++++++++++++++++++++
 gcc/testsuite/g++.dg/Wstring-plus-char-1.C     | 16 +++++++++++++
 gcc/testsuite/g++.dg/Wstring-plus-char-2.C     | 26 +++++++++++++++++++++
 gcc/testsuite/g++.dg/Wstring-plus-char-3.C     | 32 ++++++++++++++++++++++++++
 4 files changed, 100 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/Wstring-plus-char.c
 create mode 100644 gcc/testsuite/g++.dg/Wstring-plus-char-1.C
 create mode 100644 gcc/testsuite/g++.dg/Wstring-plus-char-2.C
 create mode 100644 gcc/testsuite/g++.dg/Wstring-plus-char-3.C
--
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University
[-- Attachment #2: 0005-New-tests-for-Wstring-plus-char.patch --]
[-- Type: text/x-patch, Size: 3635 bytes --]
diff --git a/gcc/testsuite/c-c++-common/Wstring-plus-char.c b/gcc/testsuite/c-c++-common/Wstring-plus-char.c
new file mode 100644
index 0000000..6d07750
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wstring-plus-char.c
@@ -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" } */
+}
diff --git a/gcc/testsuite/g++.dg/Wstring-plus-char-1.C b/gcc/testsuite/g++.dg/Wstring-plus-char-1.C
new file mode 100644
index 0000000..98f6b66
--- /dev/null
+++ b/gcc/testsuite/g++.dg/Wstring-plus-char-1.C
@@ -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" } */
+}
diff --git a/gcc/testsuite/g++.dg/Wstring-plus-char-2.C b/gcc/testsuite/g++.dg/Wstring-plus-char-2.C
new file mode 100644
index 0000000..4bb2ba3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/Wstring-plus-char-2.C
@@ -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" } */
+}
diff --git a/gcc/testsuite/g++.dg/Wstring-plus-char-3.C b/gcc/testsuite/g++.dg/Wstring-plus-char-3.C
new file mode 100644
index 0000000..a313059
--- /dev/null
+++ b/gcc/testsuite/g++.dg/Wstring-plus-char-3.C
@@ -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
next prev parent reply other threads:[~2017-06-12 1:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-12 1:26 [PATCH 0/6] " Xi Ruoyao
2017-06-12 1:31 ` [PATCH 1/6] " Xi Ruoyao
2017-06-12 1:32 ` [PATCH 2/6] " Xi Ruoyao
2017-06-19 16:51 ` Martin Sebor
2017-06-19 17:28 ` Xi Ruoyao
2017-06-19 18:44 ` Martin Sebor
2017-06-19 19:36 ` Xi Ruoyao
2017-06-22 10:26 ` Xi Ruoyao
2017-07-15 16:33 ` Gerald Pfeifer
2017-06-12 1:34 ` [PATCH 3/6] " Xi Ruoyao
2017-06-19 16:30 ` Martin Sebor
2017-06-19 17:35 ` Xi Ruoyao
2017-06-12 1:36 ` [PATCH 4/6] " Xi Ruoyao
2017-06-12 1:39 ` [PATCH 6/6] " Xi Ruoyao
2017-06-19 16:57 ` Martin Sebor
2017-06-12 1:39 ` Xi Ruoyao [this message]
2017-06-19 12:43 ` [PING PATCH 0/6] " Xi Ruoyao
2017-06-19 16:20 ` [PATCH " Martin Sebor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1497231545.27153.15.camel@stu.xidian.edu.cn \
--to=ryxi@stu.xidian.edu.cn \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).