This is the mail archive of the gcc-prs@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++/8280: friend declaration introduces class name into namespace scope


>Number:         8280
>Category:       c++
>Synopsis:       friend declaration introduces class name into namespace scope
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 18 16:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     dbaron@fas.harvard.edu
>Release:        3.2
>Organization:
>Environment:
Configured with: ../gcc-3.2/configure --prefix=/usr/local/gcc-3.2 --enable-languages=c++ --enable-__cxa_atexit
Thread model: posix
gcc version 3.2

(on Linux 2.4.18-17.8.0smp i686, i.e., RedHat 8.0)

Also present on gcc trunk:
  gcc version 3.3 20021007 (experimental)
>Description:
According to section 7.3.1.2, clause 3, of the C++
standard:
  If a |friend| declaration in a non-local class first
  declares a class or function the friend class or
  function is a member of the innermost enclosing
  namespace.  The name of the friend is not found
  by simple name lookup until a matching declaration
  is provided in that namespace scope (either before
  or after then class declaration granting friendship).

In other words (I think), |friend class B| is allowed
even if B hasn't been declared yet, but it doesn't
declare B.

I have been told that this was not true in older
drafts of the standard.
>How-To-Repeat:
The following source code is sufficient to reproduce
the problem:
-----
class A { friend class B; };

// The name |B| should not be found yet, so this
// should not compile.
B* null_b() { return 0; }

int main() { return 0; }
-----
Compile with:
g++ -o friend -ansi -pedantic test.cpp
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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