Skip to content

Commit 8541506

Browse files
author
huqizhi
committed
[Clang][Sema] Allow access to a public template alias declaration that refers to friend's private nested type
1 parent 4fdf10f commit 8541506

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ Bug Fixes in This Version
259259
operator.
260260
Fixes (#GH83267).
261261

262+
- Allow access to a public template alias declaration that refers to friend's
263+
private nested type.
264+
Fixes (#GH25708).
265+
262266
Bug Fixes to Compiler Builtins
263267
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
264268

@@ -409,7 +413,7 @@ RISC-V Support
409413
CUDA/HIP Language Changes
410414
^^^^^^^^^^^^^^^^^^^^^^^^^
411415

412-
- PTX is no longer included by default when compiling for CUDA. Using
416+
- PTX is no longer included by default when compiling for CUDA. Using
413417
``--cuda-include-ptx=all`` will return the old behavior.
414418

415419
CUDA Support

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4342,10 +4342,17 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
43424342
InstantiatingTemplate Inst(*this, TemplateLoc, Template);
43434343
if (Inst.isInvalid())
43444344
return QualType();
4345+
if (!AliasTemplate->getDeclContext()->isFileContext()) {
4346+
ContextRAII SavedContext(*this, AliasTemplate->getDeclContext());
4347+
CanonType =
4348+
SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
4349+
AliasTemplate->getLocation(), AliasTemplate->getDeclName());
4350+
} else {
43454351

4346-
CanonType = SubstType(Pattern->getUnderlyingType(),
4347-
TemplateArgLists, AliasTemplate->getLocation(),
4348-
AliasTemplate->getDeclName());
4352+
CanonType =
4353+
SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
4354+
AliasTemplate->getLocation(), AliasTemplate->getDeclName());
4355+
}
43494356
if (CanonType.isNull()) {
43504357
// If this was enable_if and we failed to find the nested type
43514358
// within enable_if in a SFINAE context, dig out the specific

clang/test/SemaTemplate/PR25708.cpp

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

0 commit comments

Comments
 (0)