Skip to content

Commit 0f2d4fe

Browse files
committed
Add a unsupported testcase.
The implementations doesn't support the using-alias-chain usage at the moment. Tweak the implementation not crashing, and add a testcase for this
1 parent 19e432e commit 0f2d4fe

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11008,17 +11008,25 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
1100811008
if (!Template) {
1100911009
if (AliasTemplate = dyn_cast_or_null<TypeAliasTemplateDecl>(
1101011010
TemplateName.getAsTemplateDecl()); AliasTemplate) {
11011-
llvm::errs() << "alias template decl\n";
11012-
auto UnderlyingType = AliasTemplate->getTemplatedDecl()
11011+
// Unrap the sugar ElaboratedType.
11012+
auto RhsType = AliasTemplate->getTemplatedDecl()
1101311013
->getUnderlyingType()
11014-
.getDesugaredType(Context);
11014+
.getSingleStepDesugaredType(Context);
1101511015
if (const auto *TST =
11016-
UnderlyingType->getAs<TemplateSpecializationType>()) {
11017-
// normal cases: using AliasFoo = Foo<T, U>;
11016+
RhsType->getAs<TemplateSpecializationType>()) {
11017+
// The template decl in the TST can be a TypeALiasTemplateDecl if
11018+
// the right hand side of the alias is a type alias as well. E.g.
11019+
//
11020+
// template<typename T>
11021+
// using AliasFoo1 = Foo<T>; // Foo<T> is a class template specialization
11022+
//
11023+
// template<typename T>
11024+
// using AliasFoo2 = AliasFoo1<T>; // AliasFoo1<T> is a type alias
11025+
// FIXME: handle this case, we need to recursively perform deductions.
1101811026
Template = dyn_cast_or_null<ClassTemplateDecl>(
1101911027
TST->getTemplateName().getAsTemplateDecl());
1102011028
AliasRhsTemplateArgs = TST->template_arguments();
11021-
} else if (const auto *RT = UnderlyingType->getAs<RecordType>()) {
11029+
} else if (const auto *RT = RhsType->getAs<RecordType>()) {
1102211030
// cases where template arguments in the RHS of the alias are not
1102311031
// dependent. e.g.
1102411032
// using AliasFoo = Foo<bool>;

clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %clang_cc1 -fsyntax-only -Wno-c++11-narrowing -Wno-literal-conversion -std=c++20 -verify %s
2-
// expected-no-diagnostics
32

43
template<typename T>
54
struct Foo {
@@ -82,3 +81,16 @@ template<typename T>
8281
using AF = Foo<T, 1>;
8382
AF b{0};//
8483
}
84+
85+
namespace test7 {
86+
87+
template<typename T>
88+
struct Foo { Foo(T); };
89+
90+
template<typename U>
91+
using AF1 = Foo<U>;
92+
template<typename K>
93+
using AF2 = AF1<K>; // expected-note {{template is declared here}}
94+
// FIXME: support this case.
95+
AF2 b = 1; // expected-error {{alias template 'AF2' requires template arguments; argument deduction only allowed for class templates}}
96+
}

0 commit comments

Comments
 (0)