This is the mail archive of the gcc-bugs@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]

[Bug c++/13903] New: using namespace X does not work for operator new


Stock download of GCC v3.3.2 will not compile the following:

/* Demo of namespace scoping bug in GCC
by Niall Douglas
*/

typedef unsigned int size_t;

namespace FX {
	void *operator new(size_t size) throw();
}

namespace App {
	using namespace FX;
	class Foo
	{
		Foo()
		{
			// This should use FX::operator new
			// NOT cause an ambiguity error with ::operator new
			int *a=new int;
		}
	};
}

/* This claims "operator new is already defined in this scope".
However the standard permits multiple functions with the same name 
and specification to exist in the same namespace, the error is
thrown when you try to use an ambiguous one, *not* *here* */

using FX::operator new;

int main(void)
{
	/* This correctly generates an ambiguous call error */
	int *a=new int;
}

This refuses to compile with:

/home/ned/TnFOX/test2.cpp:19: error: call of overloaded `operator new(unsigned
   int)' is ambiguous
<internal>:19: error: candidates are: void* operator new(unsigned int)
/home/ned/TnFOX/test2.cpp:8: error:                 void* FX::operator
   new(unsigned int)
/home/ned/TnFOX/test2.cpp: At global scope:
/home/ned/TnFOX/test2.cpp:30: error: `operator new' is already declared in this
   scope

This error is critical because it totally breaks the use of namespaces to 
implement alternative memory allocation idioms eg; ones which throw an exception 
other than std::bad_alloc.

Cheers,
Niall Douglas

-- 
           Summary: using namespace X does not work for operator new
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: s_gccbugzilla at nedprod dot com
                CC: gcc-bugs at gcc dot gnu dot org


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


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