This is the mail archive of the gcc-patches@gcc.gnu.org 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]

Re: [C++ PATCH] Fix 21799/8271


Here's the patch for the 4.0 branch.

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2005-08-12  Giovanni Bajo  <giovannibajo@libero.it>
	    Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/21799
	PR c++/8271
        * pt.c (unify) <METHOD_TYPE>: Check this-pointer cv-qualifiers
	explicitly.

2005-08-12  Nathan Sidwell  <nathan@codesourcery.com>
	    Giovanni Bajo  <giovannibajo@libero.it>
	PR c++/21799
	PR c++/8271

	* g++.dg/template/unify8.C: New.
	* g++.dg/template/unify9.C: New.
	* g++.dg/template/unify10.C: New.

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.978.2.15
diff -c -3 -p -r1.978.2.15 pt.c
*** cp/pt.c	6 Aug 2005 22:48:05 -0000	1.978.2.15
--- cp/pt.c	12 Aug 2005 09:34:37 -0000
*************** unify (tree tparms, tree targs, tree par
*** 10246,10251 ****
--- 10246,10262 ----
        if (TREE_CODE (arg) != TREE_CODE (parm))
  	return 1;
  
+       /* CV qualifications for methods can never be deduced, they must
+   	 match exactly.  We need to check them explicitly here,
+   	 because type_unification_real treats them as any other
+   	 cvqualified parameter.  */
+       if (TREE_CODE (parm) == METHOD_TYPE
+ 	  && (!check_cv_quals_for_unify
+ 	      (UNIFY_ALLOW_NONE,
+ 	       TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (arg))),
+ 	       TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (parm))))))
+ 	return 1;
+ 
        if (unify (tparms, targs, TREE_TYPE (parm),
  		 TREE_TYPE (arg), UNIFY_ALLOW_NONE))
  	return 1;
Index: testsuite/g++.dg/template/unify8.C
===================================================================
RCS file: testsuite/g++.dg/template/unify8.C
diff -N testsuite/g++.dg/template/unify8.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/unify8.C	12 Aug 2005 09:34:37 -0000
***************
*** 0 ****
--- 1,20 ----
+ // { dg-do link }
+ 
+ // Copyright (C) 2005 Free Software Foundation, Inc.
+ // Contributed by Nathan Sidwell 7 Jul 2005 <nathan@codesourcery.com>
+ 
+ // Origin:Wolfgang Bangerth <bangerth@dealii.org>
+ // PR 21799: deduction of cvqualifiers on member functions was wrong
+ 
+ template <class T> void f (T &,       void (T::*)()      ); 
+ template <class T> void f (const T &, void (T::*)() const) {} 
+  
+ struct X { 
+     void g() const {}
+ }; 
+  
+ const X *x; 
+  
+ int main () { 
+   f (*x, &X::g); 
+ }
Index: testsuite/g++.dg/template/unify9.C
===================================================================
RCS file: testsuite/g++.dg/template/unify9.C
diff -N testsuite/g++.dg/template/unify9.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/unify9.C	12 Aug 2005 09:34:37 -0000
***************
*** 0 ****
--- 1,17 ----
+ // Copyright (C) 2005 Free Software Foundation, Inc.
+ // Contributed by Nathan Sidwell 7 Jul 2005 <nathan@codesourcery.com>
+ 
+ // Origin:Wolfgang Bangerth <bangerth@dealii.org>
+ // PR 21799: deduction of cvqualifiers on member functions was wrong
+ 
+ template <class T> void f (T &,       void (T::*)()      ); 
+  
+ struct X { 
+     void g() const {}
+ }; 
+  
+ const X *x; 
+  
+ int main () { 
+   f (*x, &X::g);  // {  dg-error "no matching function" }
+ } 
Index: testsuite/g++.dg/template/unify10.C
===================================================================
RCS file: testsuite/g++.dg/template/unify10.C
diff -N testsuite/g++.dg/template/unify10.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/unify10.C	12 Aug 2005 09:34:37 -0000
***************
*** 0 ****
--- 1,48 ----
+ // { dg-do compile }
+ // Origin: Wolfgang Bangerth <bangerth at ticam dot utexas dot edu>
+ //     and Rene Fonseca <fonseca at mip dot sdu dot dk>
+ // PR c++/8271: Check cv-qualifiers while unifying pointer to member
+ //  functions.
+ 
+ struct MyClass {
+   void mMethod() throw() {}
+   void cMethod() const throw() {}
+   void vMethod() volatile throw() {}
+   void cvMethod() const volatile throw() {}
+ };
+ 
+ template<class CLASS>
+ void mFunction(void (CLASS::* method)()) {}
+ 
+ template<class CLASS>
+ void cFunction(void (CLASS::* method)() const) {}
+ 
+ template<class CLASS>
+ void vFunction(void (CLASS::* method)() volatile) {}
+ 
+ template<class CLASS>
+ void cvFunction(void (CLASS::* method)() const volatile) {}
+ 
+ int main() {
+   mFunction(&MyClass::mMethod);
+   mFunction(&MyClass::cMethod);    // { dg-error "no matching function" }
+   mFunction(&MyClass::vMethod);    // { dg-error "no matching function" }
+   mFunction(&MyClass::cvMethod);   // { dg-error "no matching function" }
+ 
+   cFunction(&MyClass::mMethod);    // { dg-error "no matching function" }
+   cFunction(&MyClass::cMethod);
+   cFunction(&MyClass::vMethod);    // { dg-error "no matching function" }
+   cFunction(&MyClass::cvMethod);   // { dg-error "no matching function" }
+ 
+   vFunction(&MyClass::mMethod);    // { dg-error "no matching function" }
+   vFunction(&MyClass::cMethod);    // { dg-error "no matching function" }
+   vFunction(&MyClass::vMethod);
+   vFunction(&MyClass::cvMethod);   // { dg-error "no matching function" }
+ 
+   cvFunction(&MyClass::mMethod);   // { dg-error "no matching function" }
+   cvFunction(&MyClass::cMethod);   // { dg-error "no matching function" }
+   cvFunction(&MyClass::vMethod);   // { dg-error "no matching function" }
+   cvFunction(&MyClass::cvMethod);
+ 
+   return 0;
+ }

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