This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++: taking address of const object with non-const operator&

Yet another error condition whose testcase I'm not allowed to
contribute :-(

This one is pretty simple, though.  Given a class with a non-const
operator&, if we attempt to take the address of a const object,
overload resolution incorrectly chooses the member function.  The
reason is that we used to allow const qualifiers to be dropped from
the `this' argument before, but now we require -fpermissive to do so
(because pedwarn is an error unless flag_permissive).  However, the
test to decide whether a candidate function is viable does not take
flag_permissive into account, so we end up committing to a non-viable
(except for the disabled extension) candidate function, and then
reject it, whereas the Standard says overload resolution should have
found no viable function (because the set of built-in candidates set
is empty [over.match.oper]/3, third bullet), and then the built-in
operator should be used [over.match.oper]/9.  I.e., the extension is
causing us to reject a well-formed program.  Oops :-)

This patch disables the permissive viability test unless -fpermissive
is given.  It also improves the error message given for the patched
testcase, in that it now lists the candidate member functions that
failed to match, whereas earlier we'd just give a misleading error
message complained of the dropped qualifier of the implicit `this'

Ok to install?  Tested on athlon-pc-linux-gnu.

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <>

	* call.c (any_viable): Require a not-BAD match if non-permissive.

Index: gcc/cp/call.c
RCS file: /cvs/gcc/egcs/gcc/cp/call.c,v
retrieving revision 1.318
diff -u -p -r1.318 call.c
--- gcc/cp/call.c 19 Apr 2002 06:22:13 -0000 1.318
+++ gcc/cp/call.c 17 May 2002 06:37:33 -0000
@@ -2314,7 +2314,7 @@ any_viable (cands)
      struct z_candidate *cands;
   for (; cands; cands = cands->next)
-    if (pedantic ? cands->viable == 1 : cands->viable)
+    if (pedantic || !flag_permissive ? cands->viable == 1 : cands->viable)
       return 1;
   return 0;
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <>

	* g++.old-deja/g++.brendan/crash56.C (ListDProto::next): Mark as
	rejected candidate functions.

Index: gcc/testsuite/g++.old-deja/g++.brendan/crash56.C
RCS file: /cvs/gcc/egcs/gcc/testsuite/g++.old-deja/g++.brendan/crash56.C,v
retrieving revision 1.4
diff -u -p -r1.4 crash56.C
--- gcc/testsuite/g++.old-deja/g++.brendan/crash56.C 12 Dec 2001 10:32:01 -0000 1.4
+++ gcc/testsuite/g++.old-deja/g++.brendan/crash56.C 17 May 2002 06:37:39 -0000
@@ -43,8 +43,8 @@ public:
     enum Action { NORMAL, REMOVE_CURRENT };
     Vix first() const;
     void first(Vix& x) const;
-    void next(Vix& x) const;
-    void next(Vix& x, Action a = NORMAL);
+    void next(Vix& x) const; // ERROR - candidate// ERROR - candidate
+    void next(Vix& x, Action a = NORMAL); // ERROR - candidate// ERROR - candidate
     Vix last() const;
     void last(Vix& x) const;
     void prev(Vix& x) const;

Alexandre Oliva   Enjoy Guarana', see
Red Hat GCC Developer                  aoliva@{,}
CS PhD student at IC-Unicamp        oliva@{,}
Free Software Evangelist                Professional serial bug killer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]