Bug 78724 - Incorrect ambiguous reference error when template class was forward declarated as a friend
Summary: Incorrect ambiguous reference error when template class was forward declarate...
Status: RESOLVED DUPLICATE of bug 59930
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.2.1
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-07 22:05 UTC by Loïc Yhuel
Modified: 2018-03-20 20:51 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Loïc Yhuel 2016-12-07 22:05:53 UTC
namespace A {
    template<class>
    class B {
        template<class> friend class C;
    };
}

void foo()
{
    A::B<void> b;
}

namespace A {
    template<class>
    class C {
    };
}

using namespace A;

void bar()
{
    C<void> c;
}

=>
test.cpp: In function ‘void bar()’:
hello.cpp:23:5: error: reference to ‘C’ is ambiguous
     C<void> c;
     ^
test.cpp:4:38: note: candidates are: template<class> class A::C
         template<class> friend class C;
                                      ^
hello.cpp:15:11: note:                 template<class> class A::C
     class C {
           ^

Note that the error doesn't happen when using "A::C<void> c".


The bug is seen with libc++ 3.9.0 headers :
#include <map>
void foo()
{
    std::map<void*,void*>::iterator it;
}
#include <set>
using namespace std;
void bar()
{
    set<void*> s;
}
Comment 1 Richard Smith 2017-11-21 23:07:00 UTC
Probable duplicate of bug#59930 (friend class templates injected into wrong namespace).
Comment 2 Jonathan Wakely 2018-03-20 20:49:33 UTC
Fixed by r255780 so closing as a dup, as Richard suggested.

*** This bug has been marked as a duplicate of bug 59930 ***