* 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
+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.
+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):
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.
+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
/* 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);
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);
}
}
-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
@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
+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
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);
}
};
--- /dev/null
+// 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" }
+};
--- /dev/null
+// 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" }
+};
+++ /dev/null
-// 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" }
-};
// 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&();
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;
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()