Skip to content

Commit 8bda565

Browse files
authored
[Clang][Sema] Allow access to a public template alias declaration that refers to friend's private nested type (#83847)
This patch attempts to fix #25708 Current access check missed qualifier(`NestedNameSpecifier`) in friend class checking. Add it to `Records` of `EffectiveContext` by changing the `DeclContext` makes `MatchesFriend` work. Co-authored-by: huqizhi <[email protected]>
1 parent 97c0cad commit 8bda565

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ Bug Fixes to C++ Support
360360
when one of the function had more specialized templates.
361361
Fixes (`#82509 <https://github.com/llvm/llvm-project/issues/82509>`_)
362362
and (`#74494 <https://github.com/llvm/llvm-project/issues/74494>`_)
363+
- Allow access to a public template alias declaration that refers to friend's
364+
private nested type. (#GH25708).
363365

364366
Bug Fixes to AST Handling
365367
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4343,9 +4343,13 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
43434343
if (Inst.isInvalid())
43444344
return QualType();
43454345

4346-
CanonType = SubstType(Pattern->getUnderlyingType(),
4347-
TemplateArgLists, AliasTemplate->getLocation(),
4348-
AliasTemplate->getDeclName());
4346+
std::optional<ContextRAII> SavedContext;
4347+
if (!AliasTemplate->getDeclContext()->isFileContext())
4348+
SavedContext.emplace(*this, AliasTemplate->getDeclContext());
4349+
4350+
CanonType =
4351+
SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
4352+
AliasTemplate->getLocation(), AliasTemplate->getDeclName());
43494353
if (CanonType.isNull()) {
43504354
// If this was enable_if and we failed to find the nested type
43514355
// within enable_if in a SFINAE context, dig out the specific

clang/test/SemaTemplate/PR25708.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 -std=c++11 -verify %s
2+
// expected-no-diagnostics
3+
4+
struct FooAccessor
5+
{
6+
template <typename T>
7+
using Foo = typename T::Foo;
8+
};
9+
10+
class Type
11+
{
12+
friend struct FooAccessor;
13+
14+
using Foo = int;
15+
};
16+
17+
int main()
18+
{
19+
FooAccessor::Foo<Type> t;
20+
}

0 commit comments

Comments
 (0)