[Bug c++/15075] New: "using namespace" fails in part

gcc-bugzilla at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Apr 22 17:05:00 GMT 2004


"using namespace Test;" fails to tell the compiler that a friendly
function definition is within Test.  "namespace Test {...}" works fine.

Environment:
System: SunOS bioquad 5.9 Generic_112233-11 sun4u sparc SUNW,Sun-Fire-V440
Architecture: sun4

	
host: sparc-sun-solaris2.9
build: sparc-sun-solaris2.9
target: sparc-sun-solaris2.9
configured with: ../../../distribution/gcc-3.3.2/configure --prefix=/local/bioproj/people/lnewberg/install/sparc-sun-solaris2.9/gcc-3.3.2 --with-ld=/usr/ccs/bin/ld --with-as=/usr/ccs/bin/as --disable-nls --enable-languages=c,c++,objc

How-To-Repeat:
	Compile with g++ -c test2.cc
--- Begin test2.cc ---
// This file does not compile under g++.  I think it should.  See
// below.

namespace Test
{
    class A
    {
    private:
	class B
	{
	public:
	    int _b;
	};
	friend bool works1(B const &);
	friend bool works2(B const &);
	friend bool fails(B const &);
    };
} // End of namespace Test

namespace Test
{
    bool works1(A::B const &lhs)
    {
	return true;
    }
} // End of namespace Test

using namespace Test;

// Despite the "using namespace Test" directive, the function fails()
// must be declared as "Test::fails" rather than simply "fails" or the
// compiler complains that class Test::A::B is private in this
// context.
// 
// Note that the "using" directive does work to eliminate the need to
// use the explicit Test::A::B instead of the shorter A::B in the
// definition of fails() below.
// 
// Contrastingly, the functions works1(), above, and works2(), below,
// compile without error.

bool Test::works2(A::B const &)
{
    return true;
}

bool fails(A::B const &)
{
    return true;
}
--- End test2.cc ---
------- Additional Comments From lnewberg at wadsworth dot org  2004-04-22 16:55 -------
Fix:
	Use "namespace Test {...}" instead.

-- 
           Summary: "using namespace" fails in part
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lnewberg at wadsworth dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.9
  GCC host triplet: sparc-sun-solaris2.9
GCC target triplet: sparc-sun-solaris2.9


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15075



More information about the Gcc-bugs mailing list