This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/31336] New: template friends and Koenig lookup
- From: "andrew dot olson at hughes dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Mar 2007 20:54:15 -0000
- Subject: [Bug c++/31336] New: template friends and Koenig lookup
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Koenig lookup doesn't seem to work properly when dealing with template friends
defined within a class. Friends defined within the definition of a class
shouldn't be visible to the enclosing namespace, and should only be able to be
found via Koenig lookup. I see that this appears to work as expected for
normal friends, but GCC still appears make the name visible for template
friends.
I think that this behaviour is incorrect, but could I be missing something?
The Comeau C++ with EDG front end seems to agree with my reading of the spec,
but then its possible that its behaviour is incorrect instead.
In the following test program, I think that tests #5 and #7 should fail to
compile, but do not. Neither bar(int, int) and bar(Foo, int) contain an
associated class to class Bar and therefore should not be found.
Thanks!
Andy
#include <iostream>
struct Bar;
struct Foo
{
Foo() { }
Foo(const Bar &src) { std::cout << "Bar->Foo" << std::endl; }
Foo(int src) { std::cout << "int->Foo" << std::endl; }
friend void foo(const Foo &a, int b)
{
std::cout << "Foo " << b << std::endl;
}
};
struct Bar
{
operator int() { return(9); } // for test 9
template<typename A, typename B>
friend void bar(const A &a, B b)
{
std::cout << "Bar " << b << std::endl;
}
};
int main(int argc, char *argv[])
{
Foo f;
Bar b;
//foo(1, 0); // #0 - EDG, MSVC 8, GCC 4.1.2 no yes via conversion ctor
foo((Foo)1, 1); // #1 ok via conv ctor
foo(f, 2); // #2 ok
//foo(b, 3); // #3 EDG no, GCC 4.1.2 no, MSVC 8 yes via conv ctor
foo((Foo)b, 4); // #4 ok via conv ctor
bar(1, 5); // #5 EDG, MSVC 8 no, GCC 4.1.2 yes
bar(b, 6); // #6 ok
bar(f, 7); // #7 EDG no, MSVC 8, GCC 4.1.2 yes
bar(b, "8"); // #8 ok
bar(f, b); // #9 ok
return(0);
}
--
Summary: template friends and Koenig lookup
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: andrew dot olson at hughes dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31336