aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2018-09-20 01:56:58 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2018-09-20 01:56:58 +0000
commita599af84b2170d8d66385674ef59283ac7567beb (patch)
treebf068ca7002b41bbcd5a22acbec77ab45d67f0ac /gcc
parentcf16d179d570e9a5535267b92e0f9e71756483b0 (diff)
downloadgcc-a599af84b2170d8d66385674ef59283ac7567beb.zip
gcc-a599af84b2170d8d66385674ef59283ac7567beb.tar.gz
gcc-a599af84b2170d8d66385674ef59283ac7567beb.tar.bz2
Add -Wclass-conversion.
* c.opt (Wclass-conversion): New. * decl.c (grok_op_properties): Change a warning from -Wconversion to -Wclass-conversion. Make it print the types. * doc/invoke.texi: Document -Wclass-conversion. * g++.dg/conversion/op4.C: Add dg-warning. * g++.dg/warn/Wclass-conversion1.C: New test. * g++.dg/warn/Wclass-conversion2.C: New test. * g++.dg/warn/Wconversion5.C: Remove file. * g++.dg/warn/conversion-function-1.C: Use -Wno-class-converison. * g++.old-deja/g++.bugs/900215_01.C: Adjust dg-warning. * g++.old-deja/g++.jason/conversion5.C: Likewise. From-SVN: r264438
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog4
-rw-r--r--gcc/c-family/ChangeLog4
-rw-r--r--gcc/c-family/c.opt4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/decl.c26
-rw-r--r--gcc/doc/invoke.texi8
-rw-r--r--gcc/testsuite/ChangeLog10
-rw-r--r--gcc/testsuite/g++.dg/conversion/op4.C2
-rw-r--r--gcc/testsuite/g++.dg/warn/Wclass-conversion1.C19
-rw-r--r--gcc/testsuite/g++.dg/warn/Wclass-conversion2.C20
-rw-r--r--gcc/testsuite/g++.dg/warn/Wconversion5.C20
-rw-r--r--gcc/testsuite/g++.dg/warn/conversion-function-1.C2
-rw-r--r--gcc/testsuite/g++.old-deja/g++.bugs/900215_01.C2
-rw-r--r--gcc/testsuite/g++.old-deja/g++.jason/conversion5.C2
14 files changed, 93 insertions, 36 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 729fb57..728799d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,7 @@
+2018-09-19 Marek Polacek <polacek@redhat.com>
+
+ * doc/invoke.texi: Document -Wclass-conversion.
+
2018-09-19 John David Anglin <danglin@gcc.gnu.org>
* config/pa/pa.c (pa_adjust_priority): Delete.
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index f2ec394..8fc773c 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,7 @@
+2018-09-19 Marek Polacek <polacek@redhat.com>
+
+ * c.opt (Wclass-conversion): New.
+
2018-09-17 David Malcolm <dmalcolm@redhat.com>
* c-format.c (range_label_for_format_type_mismatch::get_text):
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 092ec94..43d1d27 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -850,6 +850,10 @@ Wnon-template-friend
C++ ObjC++ Var(warn_nontemplate_friend) Init(1) Warning
Warn when non-templatized friend functions are declared within a template.
+Wclass-conversion
+C++ ObjC++ Var(warn_class_conversion) Init(1) Warning
+Warn when a conversion function will never be called due to the type it converts to.
+
Wclass-memaccess
C++ ObjC++ Var(warn_class_memaccess) Warning LangEnabledBy(C++ ObjC++, Wall)
Warn for unsafe raw memory writes to objects of class types.
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 546943c..75286d5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-09-19 Marek Polacek <polacek@redhat.com>
+
+ Add -Wclass-conversion.
+ * decl.c (grok_op_properties): Change a warning from -Wconversion to
+ -Wclass-conversion. Make it print the types.
+
2018-09-19 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/87324
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 503b433..2d9d56e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13544,7 +13544,7 @@ grok_op_properties (tree decl, bool complain)
/* Warn about conversion operators that will never be used. */
if (IDENTIFIER_CONV_OP_P (name)
&& ! DECL_TEMPLATE_INFO (decl)
- && warn_conversion)
+ && warn_class_conversion)
{
tree t = TREE_TYPE (name);
int ref = TYPE_REF_P (t);
@@ -13553,27 +13553,29 @@ grok_op_properties (tree decl, bool complain)
t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
if (VOID_TYPE_P (t))
- warning_at (loc, OPT_Wconversion, "conversion to void "
- "will never use a type conversion operator");
+ warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
+ "will never use a type conversion operator", class_type);
else if (class_type)
{
if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
- warning_at (loc, OPT_Wconversion,
+ warning_at (loc, OPT_Wclass_conversion,
ref
- ? G_("conversion to a reference to the same type "
+ ? G_("converting %qT to a reference to the same type "
"will never use a type conversion operator")
- : G_("conversion to the same type "
- "will never use a type conversion operator"));
+ : G_("converting %qT to the same type "
+ "will never use a type conversion operator"),
+ class_type);
/* Don't force t to be complete here. */
else if (MAYBE_CLASS_TYPE_P (t)
&& COMPLETE_TYPE_P (t)
&& DERIVED_FROM_P (t, class_type))
- warning_at (loc, OPT_Wconversion,
+ warning_at (loc, OPT_Wclass_conversion,
ref
- ? G_("conversion to a reference to a base class "
- "will never use a type conversion operator")
- : G_("conversion to a base class "
- "will never use a type conversion operator"));
+ ? G_("converting %qT to a reference to a base class "
+ "%qT will never use a type conversion operator")
+ : G_("converting %qT to a base class %qT "
+ "will never use a type conversion operator"),
+ class_type, t);
}
}
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 685c211..aab5fce 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -237,6 +237,7 @@ in the following sections.
-Weffc++ -Wstrict-null-sentinel -Wtemplates @gol
-Wno-non-template-friend -Wold-style-cast @gol
-Woverloaded-virtual -Wno-pmf-conversions @gol
+-Wno-class-conversion -Wno-terminate @gol
-Wsign-promo -Wvirtual-inheritance}
@item Objective-C and Objective-C++ Language Options
@@ -3367,6 +3368,13 @@ use the STL. One may also use using directives and qualified names.
@opindex Wno-terminate
Disable the warning about a throw-expression that will immediately
result in a call to @code{terminate}.
+
+@item -Wno-class-conversion @r{(C++ and Objective-C++ only)}
+@opindex Wno-class-conversion
+@opindex Wclass-conversion
+Disable the warning about the case when a conversion function converts an
+object to the same type, to a base class of that type, or to void; such
+a conversion function will never be called.
@end table
@node Objective-C and Objective-C++ Dialect Options
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f3b55d1..25f61d2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2018-09-19 Marek Polacek <polacek@redhat.com>
+
+ * g++.dg/conversion/op4.C: Add dg-warning.
+ * g++.dg/warn/Wclass-conversion1.C: New test.
+ * g++.dg/warn/Wclass-conversion2.C: New test.
+ * g++.dg/warn/Wconversion5.C: Remove file.
+ * g++.dg/warn/conversion-function-1.C: Use -Wno-class-converison.
+ * g++.old-deja/g++.bugs/900215_01.C: Adjust dg-warning.
+ * g++.old-deja/g++.jason/conversion5.C: Likewise.
+
2018-09-19 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/87324
diff --git a/gcc/testsuite/g++.dg/conversion/op4.C b/gcc/testsuite/g++.dg/conversion/op4.C
index cb99a38..3fb850c 100644
--- a/gcc/testsuite/g++.dg/conversion/op4.C
+++ b/gcc/testsuite/g++.dg/conversion/op4.C
@@ -4,7 +4,7 @@
struct X {
int x;
X (int i = 0) : x (i) {}
- operator X& (void) const {
+ operator X& (void) const { // { dg-warning "will never use" }
return *(new X);
}
};
diff --git a/gcc/testsuite/g++.dg/warn/Wclass-conversion1.C b/gcc/testsuite/g++.dg/warn/Wclass-conversion1.C
new file mode 100644
index 0000000..2599a53
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wclass-conversion1.C
@@ -0,0 +1,19 @@
+// PR c++/87357
+// { dg-do compile }
+
+struct B { };
+
+struct X : public B {
+ operator X(); // { dg-warning "3:converting .X. to the same type will never use a type conversion operator" }
+ operator X&(); // { dg-warning "3:converting .X. to a reference to the same type will never use a type conversion operator" }
+ operator X() const; // { dg-warning "3:converting .X. to the same type will never use a type conversion operator" }
+ operator const X(); // { dg-warning "3:converting .X. to the same type will never use a type conversion operator" }
+
+ operator B(); // { dg-warning "3:converting .X. to a base class .B. will never use a type conversion operator" }
+ operator B&(); // { dg-warning "3:converting .X. to a reference to a base class .B. will never use a type conversion operator" }
+ operator B() const; // { dg-warning "3:converting .X. to a base class .B. will never use a type conversion operator" }
+ operator const B(); // { dg-warning "3:converting .X. to a base class .const B. will never use a type conversion operator" }
+
+ operator void(); // { dg-warning "3:converting .X. to .void. will never use a type conversion operator" }
+ operator void() const; // { dg-warning "3:converting .X. to .void. will never use a type conversion operator" }
+};
diff --git a/gcc/testsuite/g++.dg/warn/Wclass-conversion2.C b/gcc/testsuite/g++.dg/warn/Wclass-conversion2.C
new file mode 100644
index 0000000..b6919f0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wclass-conversion2.C
@@ -0,0 +1,20 @@
+// PR c++/87357
+// { dg-do compile }
+// { dg-options "-Wno-class-conversion" }
+
+struct B { };
+
+struct X : public B {
+ operator X(); // { dg-bogus "3:converting .X. to the same type will never use a type conversion operator" }
+ operator X&(); // { dg-bogus "3:converting .X. to a reference to the same type will never use a type conversion operator" }
+ operator X() const; // { dg-bogus "3:converting .X. to the same type will never use a type conversion operator" }
+ operator const X(); // { dg-bogus "3:converting .X. to the same type will never use a type conversion operator" }
+
+ operator B(); // { dg-bogus "3:converting .X. to a base class .B. will never use a type conversion operator" }
+ operator B&(); // { dg-bogus "3:converting .X. to a reference to a base class .B. will never use a type conversion operator" }
+ operator B() const; // { dg-bogus "3:converting .X. to a base class .B. will never use a type conversion operator" }
+ operator const B(); // { dg-bogus "3:converting .X. to a base class .const B. will never use a type conversion operator" }
+
+ operator void(); // { dg-bogus "3:converting .X. to .void. will never use a type conversion operator" }
+ operator void() const; // { dg-bogus "3:converting .X. to .void. will never use a type conversion operator" }
+};
diff --git a/gcc/testsuite/g++.dg/warn/Wconversion5.C b/gcc/testsuite/g++.dg/warn/Wconversion5.C
deleted file mode 100644
index 00b1dda..0000000
--- a/gcc/testsuite/g++.dg/warn/Wconversion5.C
+++ /dev/null
@@ -1,20 +0,0 @@
-// 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" }
-};
diff --git a/gcc/testsuite/g++.dg/warn/conversion-function-1.C b/gcc/testsuite/g++.dg/warn/conversion-function-1.C
index 878011c..890719b 100644
--- a/gcc/testsuite/g++.dg/warn/conversion-function-1.C
+++ b/gcc/testsuite/g++.dg/warn/conversion-function-1.C
@@ -1,6 +1,6 @@
// Copyright (C) 2003 Free Software Foundation
// Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
-// { dg-options "-Wno-conversion" }
+// { dg-options "-Wno-class-conversion" }
struct A {
operator A&();
diff --git a/gcc/testsuite/g++.old-deja/g++.bugs/900215_01.C b/gcc/testsuite/g++.old-deja/g++.bugs/900215_01.C
index 0cd9b32..fd07568 100644
--- a/gcc/testsuite/g++.old-deja/g++.bugs/900215_01.C
+++ b/gcc/testsuite/g++.old-deja/g++.bugs/900215_01.C
@@ -24,7 +24,7 @@
struct struct0 {
- operator void (); // { dg-warning "3:conversion to void will never use a type conversion operator" }
+ operator void (); // { dg-warning "3:converting .struct0. to .void. will never use a type conversion operator" }
};
int exit_status = 1;
diff --git a/gcc/testsuite/g++.old-deja/g++.jason/conversion5.C b/gcc/testsuite/g++.old-deja/g++.jason/conversion5.C
index a9531a6..7f04de4 100644
--- a/gcc/testsuite/g++.old-deja/g++.jason/conversion5.C
+++ b/gcc/testsuite/g++.old-deja/g++.jason/conversion5.C
@@ -3,7 +3,7 @@
struct A { };
struct B: public A {
A a;
- operator A () { return a; } // { dg-warning "3:conversion to a base class will never use a type conversion operator" }
+ operator A () { return a; } // { dg-warning "3:converting .B. to a base class .A. will never use a type conversion operator" }
};
void f (const A&);
void g()