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]

c++/1016: friend class declarations not observing namespace rules.



>Number:         1016
>Category:       c++
>Synopsis:       friend class declarations not observing namespace rules.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 07 21:46:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Jay Cox
>Release:        2.95.2
>Organization:
>Environment:
debian woody i386
>Description:
Friend class declarations inside of namespaces are not handled
properly.  They should not automaticaly cross namespace boundaries.

Example Code:
//---------------------------------------
class b {};

namespace foo
{
  class a
  {
    friend class b;
    b b_;
  };
}
//----------------------------------

This code compiles fine under g++ 2.95.2 but should give the
error:
test.cc:11: field `b_' has incomplete type

Relevant section from the spec:
(7.3.1.2 paragraph 3)
"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.
... When looking for a prior declaration of a class or a function declared as a
friend, scopes outside the innermost enclosing namespace scope are not
considered"

This bug may seem pretty pedantic, but really bad things
can happen if code like this is allowed through the compiler.

Thanks,
Jay Cox
jaycox@gimp.org
>How-To-Repeat:
compile code included in description
>Fix:
add a class ...; statement just before the friend statement???
>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]