Skip to content

Commit

Permalink
PR37556: Don't diagnose conflicts between instantiated unqualified
Browse files Browse the repository at this point in the history
friend declarations and declarations found in inline namespaces within
the target context.
  • Loading branch information
zygoloid committed Aug 25, 2020
1 parent e02d081 commit 04ba185
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,13 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
// typedef (C++ [dcl.typedef]p4).
if (Previous.isSingleTagDecl())
Previous.clear();

// Filter out previous declarations that don't match the scope. The only
// effect this has is to remove declarations found in inline namespaces
// for friend declarations with unqualified names.
SemaRef.FilterLookupForScope(Previous, DC, /*Scope*/ nullptr,
/*ConsiderLinkage*/ true,
QualifierLoc.hasQualifier());
}

SemaRef.CheckFunctionDeclaration(/*Scope*/ nullptr, Function, Previous,
Expand Down
19 changes: 19 additions & 0 deletions clang/test/SemaTemplate/friend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,22 @@ namespace qualified_friend_finds_nothing {
namespace N { void f(int); }
B<int> bi; // ok?!
}

namespace PR37556 {
inline namespace N { int x1, x2, y1, y2; } // expected-note 2{{previous}}
struct X {
friend void x1(int);
friend void PR37556::x2(int); // expected-error {{different kind}}
};
template<typename T> struct Y {
friend void y1(T);
friend void PR37556::y2(T); // expected-error {{different kind}}
};
template struct Y<int>;
template<typename T> struct Z {
friend void z1(T);
friend void PR37556::z2(T); // expected-error {{does not match any}}
};
inline namespace N { int z1, z2; }
template struct Z<int>;
}

0 comments on commit 04ba185

Please sign in to comment.