From: Marek Polacek Date: Wed, 19 Sep 2018 16:59:51 +0000 (+0000) Subject: PR c++/87357 - missing -Wconversion warning X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fce33808678df40cce69c15141926342f8a6f47e;p=gcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7ea4b6d0f2e..7fcb34605c1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-09-19 Marek Polacek + + 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 P1064R0 - Allowing Virtual Function Calls in Constant Expressions diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 827c1720335..503b433cbd1 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 c2739e8b7bb..f52f37b6a1f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-09-19 Marek Polacek + + PR c++/87357 - missing -Wconversion warning + * g++.dg/warn/Wconversion5.C: New test. + 2018-09-19 Matthew Malcomson * 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 00000000000..00b1ddab188 --- /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" } +};