This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
A warning option for confusing overload resolution
- To: egcs-patches at cygnus dot com
- Subject: A warning option for confusing overload resolution
- From: Tobias Ringstrom <tori at prosolvia dot se>
- Date: Tue, 14 Jul 1998 11:27:29 +0200 (CEST)
- Cc: jason at cygnus dot com
- Organization: Prosolvia AB
The enclosed patch defines a new warning option (-Woverload-sequence) for
warnings such as the following.
qstring.h:340: warning: choosing `QString::operator const char *() const' over
`QArrayT<char>::operator const char *<char>() const'
qstring.h:340: warning: for conversion from `const QString' to `const char *'
qstring.h:340: warning: because conversion sequence for the argument is better
I could not find a way to disable this warning. The warning is especially
annoying since the code is perfectly correct, and there is no way to rewrite
the code to get rid of the warning (without using explicit casting). Or is
there? Anyway, you get zillions of these warnings when compiling Qt. As Qt is
the foundation of KDE, I expect a lot of people will run into this.
I chose to disable the warning by default and not to include it in -Wall.
It would be great if this could make it into egcs-1.1, of course. :-)
Comments?
/ Tobias
Index: invoke.texi
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/invoke.texi,v
retrieving revision 1.55
diff -u -r1.55 invoke.texi
--- invoke.texi 1998/07/12 01:25:52 1.55
+++ invoke.texi 1998/07/14 08:59:05
@@ -129,7 +129,7 @@
-Wshadow -Wsign-compare -Wstrict-prototypes -Wswitch
-Wsynth -Wtemplate-debugging -Wtraditional -Wtrigraphs
-Wundef -Wuninitialized -Wunused -Wwrite-strings
--Wunknown-pragmas
+-Wunknown-pragmas -Woverload-sequence
@end smallexample
@item Debugging Options
@@ -1182,6 +1182,7 @@
@item -Wold-style-cast
@itemx -Woverloaded-virtual
@itemx -Wtemplate-debugging
+@itemx -Woverload-sequence
Warnings that apply only to C++ programs. @xref{Warning
Options,,Options to Request or Suppress Warnings}.
@@ -1676,6 +1677,29 @@
@item -Wold-style-cast
Warn if an old-style (C-style) cast is used within a program.
+
+@item -Woverload-sequence
+Warn about confusing overload resolution.
+
+@smallexample
+class A @{
+public:
+ operator char *();
+ operator const char *() const;
+@};
+
+void f(const char *s);
+
+int main()
+@{
+ A a;
+ f(a);
+@}
+@end smallexample
+
+In this example, @samp{a} is converted to @samp{const char*} using the
+conversion sequence @samp{A => char* => const char*}, not using @samp{A
+=> const A => const char*}, which may be expected.
@item -Woverloaded-virtual
@cindex overloaded virtual fn, warning
Index: cp/call.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/call.c,v
retrieving revision 1.92
diff -u -r1.92 call.c
--- call.c 1998/06/23 01:48:58 1.92
+++ call.c 1998/07/14 08:59:15
@@ -4315,7 +4315,7 @@
}
/* warn about confusing overload resolution */
- if (winner && cand1->second_conv
+ if (warn_overload_sequence && winner && cand1->second_conv
&& (! DECL_CONSTRUCTOR_P (cand1->fn)
|| ! DECL_CONSTRUCTOR_P (cand2->fn)))
{
Index: cp/cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.98
diff -u -r1.98 cp-tree.h
--- cp-tree.h 1998/07/12 16:55:15 1.98
+++ cp-tree.h 1998/07/14 08:59:21
@@ -411,6 +411,10 @@
extern int warn_old_style_cast;
+/* Nonzero means warn about confusing overload resolution. */
+
+extern int warn_overload_sequence;
+
/* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
extern int flag_signed_bitfields;
Index: cp/decl2.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl2.c,v
retrieving revision 1.96
diff -u -r1.96 decl2.c
--- decl2.c 1998/07/12 16:55:16 1.96
+++ decl2.c 1998/07/14 08:59:27
@@ -292,6 +292,10 @@
int warn_unknown_pragmas; /* Tri state variable. */
+/* Nonzero means warn about confusing overload resolution. */
+
+int warn_overload_sequence;
+
/* Nonzero means warn about use of multicharacter literals. */
int warn_multichar = 1;
@@ -734,6 +738,8 @@
warn_sign_promo = setting;
else if (!strcmp (p, "old-style-cast"))
warn_old_style_cast = setting;
+ else if (!strcmp (p, "overload-sequence"))
+ warn_overload_sequence = setting;
else if (!strcmp (p, "overloaded-virtual"))
warn_overloaded_virtual = setting;
else if (!strcmp (p, "multichar"))
Index: cp/lang-options.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/lang-options.h,v
retrieving revision 1.9
diff -u -r1.9 lang-options.h
--- lang-options.h 1998/07/07 11:24:49 1.9
+++ lang-options.h 1998/07/14 08:59:28
@@ -101,6 +101,8 @@
"-Wno-return-type",
"-Woverloaded-virtual",
"-Wno-overloaded-virtual",
+ "-Woverload-sequence",
+ "-Wno-overload-sequence",
"-Wctor-dtor-privacy",
"-Wno-ctor-dtor-privacy",
"-Wnon-virtual-dtor",