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]

C++ PATCH: PR 23842


This PR is about a tricky access control case: the access checking for
a default argument takes place within the context of the function
declaring the default argument, not within the caller.

"If a function template f is called in a way that requires a default
argument expression to be used, the dependent names are looked up, the
semantics constraints are checked, and the instantiation of any
template used in the default argument expression is done as if the
default argument expression had been an expression used in a function
template specialization with the same scope, the same template parame-
ters and the same access as that of the function template f used at
that point."

Tested on x86_64-unknown-linux-gnu, applied on the mainline and on the
4.0 branch.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-09-13  Mark Mitchell  <mark@codesourcery.com>

	PR c++/23842
	* pt.c (tsubst_default_argument): Do treat default argument
	expressions as occurring in the context of the function called. 

2005-09-13  Mark Mitchell  <mark@codesourcery.com>

	PR c++/23842
	* g++.dg/template/access16.C: New test.

Index: gcc/cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.1033
diff -c -5 -p -r1.1033 pt.c
*** gcc/cp/pt.c	12 Sep 2005 22:38:23 -0000	1.1033
--- gcc/cp/pt.c	13 Sep 2005 07:50:52 -0000
*************** tsubst_default_argument (tree fn, tree t
*** 6095,6108 ****
         };
  
       we must be careful to do name lookup in the scope of S<T>,
       rather than in the current class.  */
    push_access_scope (fn);
-   /* The default argument expression should not be considered to be
-      within the scope of FN.  Since push_access_scope sets
-      current_function_decl, we must explicitly clear it here.  */
-   current_function_decl = NULL_TREE;
    /* The "this" pointer is not valid in a default argument.  */
    if (cfun)
      {
        saved_class_ptr = current_class_ptr;
        cp_function_chain->x_current_class_ptr = NULL_TREE;
--- 6095,6104 ----
Index: gcc/testsuite/g++.dg/template/access16.C
===================================================================
RCS file: gcc/testsuite/g++.dg/template/access16.C
diff -N gcc/testsuite/g++.dg/template/access16.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/g++.dg/template/access16.C	13 Sep 2005 07:50:56 -0000
***************
*** 0 ****
--- 1,16 ----
+ // PR c++/23842
+ 
+ struct S;
+ extern S *p;
+ template <class T> int f(T*, int y = ((T*)p)->x) {
+ 	return y;
+ }
+ struct S {
+ private:
+   int x;
+   template <class U> friend int f(U*, int);
+ };
+ int g() {
+   return f(p);
+ }
+ 			   


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