aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2018-09-19 16:59:51 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2018-09-19 16:59:51 +0000
commitfce33808678df40cce69c15141926342f8a6f47e (patch)
treee6d37b69917713dcc5c8791dc8d9031993c251ec
parent3c2a8ed0d9a56a45a67f87c5fa3a093c6852e62b (diff)
downloadgcc-fce33808678df40cce69c15141926342f8a6f47e.zip
gcc-fce33808678df40cce69c15141926342f8a6f47e.tar.gz
gcc-fce33808678df40cce69c15141926342f8a6f47e.tar.bz2
PR c++/87357 - missing -Wconversion warning
PR c++/87357 - missing -Wconversion warning * decl.c (grok_op_properties): Remove diagnostic parts mentioning a conversion to a reference to void. Use same_type_ignoring_top_level_qualifiers_p rather than comparing types directly. * g++.dg/warn/Wconversion5.C: New test. From-SVN: r264425
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/decl.c10
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/warn/Wconversion5.C20
4 files changed, 36 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 7ea4b6d..7fcb346 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2018-09-19 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87357 - missing -Wconversion warning
+ * decl.c (grok_op_properties): Remove diagnostic parts mentioning
+ a conversion to a reference to void. Use
+ same_type_ignoring_top_level_qualifiers_p rather than comparing types
+ directly.
+
2018-09-18 Marek Polacek <polacek@redhat.com>
P1064R0 - Allowing Virtual Function Calls in Constant Expressions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 827c172..503b433 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13553,15 +13553,11 @@ grok_op_properties (tree decl, bool complain)
t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
if (VOID_TYPE_P (t))
- warning_at (loc, OPT_Wconversion,
- ref
- ? G_("conversion to a reference to void "
- "will never use a type conversion operator")
- : G_("conversion to void "
- "will never use a type conversion operator"));
+ warning_at (loc, OPT_Wconversion, "conversion to void "
+ "will never use a type conversion operator");
else if (class_type)
{
- if (t == class_type)
+ if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
warning_at (loc, OPT_Wconversion,
ref
? G_("conversion to a reference to the same type "
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c2739e8..f52f37b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-09-19 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87357 - missing -Wconversion warning
+ * g++.dg/warn/Wconversion5.C: New test.
+
2018-09-19 Matthew Malcomson <matthew.malcomson@arm.com>
* gcc.target/aarch64/atomic-store.c: New.
diff --git a/gcc/testsuite/g++.dg/warn/Wconversion5.C b/gcc/testsuite/g++.dg/warn/Wconversion5.C
new file mode 100644
index 0000000..00b1dda
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wconversion5.C
@@ -0,0 +1,20 @@
+// PR c++/87357
+// { dg-do compile }
+// { dg-options "-Wconversion" }
+
+struct B { };
+
+struct X : public B {
+ operator X(); // { dg-warning "3:conversion to the same type will never use a type conversion operator" }
+ operator X&(); // { dg-warning "3:conversion to a reference to the same type will never use a type conversion operator" }
+ operator X() const; // { dg-warning "3:conversion to the same type will never use a type conversion operator" }
+ operator const X(); // { dg-warning "3:conversion to the same type will never use a type conversion operator" }
+
+ operator B(); // { dg-warning "3:conversion to a base class will never use a type conversion operator" }
+ operator B&(); // { dg-warning "3:conversion to a reference to a base class will never use a type conversion operator" }
+ operator B() const; // { dg-warning "3:conversion to a base class will never use a type conversion operator" }
+ operator const B(); // { dg-warning "3:conversion to a base class will never use a type conversion operator" }
+
+ operator void(); // { dg-warning "3:conversion to void will never use a type conversion operator" }
+ operator void() const; // { dg-warning "3:conversion to void will never use a type conversion operator" }
+};