From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31174 invoked by alias); 31 Oct 2002 16:46:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 31148 invoked by uid 71); 31 Oct 2002 16:46:02 -0000 Date: Thu, 31 Oct 2002 08:46:00 -0000 Message-ID: <20021031164602.31144.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Christoph Ludwig Subject: Re: c++/7522: access by friend function's default argument Reply-To: Christoph Ludwig X-SW-Source: 2002-10/txt/msg01334.txt.bz2 List-Id: The following reply was made to PR c++/7522; it has been noted by GNATS. From: Christoph Ludwig To: bangerth@dealii.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Cc: Subject: Re: c++/7522: access by friend function's default argument Date: Thu, 31 Oct 2002 17:43:00 +0100 On Wed, Oct 30, 2002 at 11:32:04PM -0000, bangerth@dealii.org wrote: > Synopsis: access by friend function's default argument > > State-Changed-From-To: open->feedback > State-Changed-By: bangerth > State-Changed-When: Wed Oct 30 15:32:03 2002 > State-Changed-Why: > I don't think this is a bug. 11.0.7 states: > 7 The names in a default argument expression (_dcl.fct.default_) are > bound at the point of declaration, and access is checked at that point > rather than at any points of use of the default argument expression. > > I don't see anything right away in the standard that for > checking access to the names used in the default value has > to happen inside the scope of the function that uses them, > but common reasoning would suggest that the enclosing scope > is used, in which case the befriended function is not > taken into account. > > I'll put this report into feedback mode. Please let us know > if you can follow my reasoning, or whether we shall reopen > the report. > > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7522 I admit I am not totally sure about this. Prior to submitting the PR, I asked for clarification in comp.lang.c++.moderated and comp.std.c++, but whithout success. The reference to 11.0.7 does not totally convince me; as I read it, the default argument expression has to undergo the same access checks as any other name bound in the parameter list of the function declaration. When I prepared an example I found g++ 3.2 seems to apply the rules inconsistently. Please consider: class A { private: class AInner { public: AInner(int i); }; static const AInner ai; friend void f1(const A::AInner& x); friend void f2(const A::AInner& x); friend void f3(const A::AInner& x); }; const A::AInner A::ai(5); void f1(const A::AInner& x); // ok void f2(const A::AInner& x = A::AInner(5)); // ok void f3(const A::AInner& x = A::ai); // error If I follow your reasoning, then all three function declarations should be flagged as erroneous, I think. But g++ 3.2 complains about the last declaration only. Even if I conceded that only the default argument expressions in this example should be checked at namespace scope for access violations: Why should the constructor of the private member class A::AInner be accessible, but not the private static member variable A::ai? For what it is worth, Comeau 4.3 accepts the above code. Regards Christoph -- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA-CA: http://www.informatik.tu-darmstadt.de/TI/Forschung/LiDIA-CA/