Skip to content

Commit 5212f12

Browse files
committed
[Clang] prevent errors for deduction guides using deduced type aliases
1 parent 56feea7 commit 5212f12

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ Improvements to Clang's diagnostics
583583
- For an rvalue reference bound to a temporary struct with an integer member, Clang will detect constant integer overflow
584584
in the initializer for the integer member (#GH46755).
585585

586+
- Clang now prevents errors for deduction guides with deduced type aliases (#GH54909).
587+
586588
Improvements to Clang's time-trace
587589
----------------------------------
588590

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11451,7 +11451,11 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
1145111451
bool MightInstantiateToSpecialization = false;
1145211452
if (auto RetTST =
1145311453
TSI->getTypeLoc().getAsAdjusted<TemplateSpecializationTypeLoc>()) {
11454-
TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName();
11454+
const TemplateSpecializationType *TST = RetTST.getTypePtr();
11455+
while (TST->isTypeAlias())
11456+
TST = TST->getAliasedType()->getAs<TemplateSpecializationType>();
11457+
11458+
TemplateName SpecifiedName = TST->getTemplateName();
1145511459
bool TemplateMatches = Context.hasSameTemplateName(
1145611460
SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true);
1145711461

clang/test/CXX/temp/temp.deduct.guide/p3.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ template<template<typename> typename TT> struct E { // expected-note 2{{template
3333
};
3434

3535
A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is not a specialization of template 'A'}}
36-
template <typename T> A(T)->B<T>; // expected-error {{deduced type 'B<T>' (aka 'A<T>') of deduction guide is not written as a specialization of template 'A'}}
36+
template <typename T> A(T)->B<T>;
3737
template<typename T> A(T*) -> const A<T>; // expected-error {{deduced type 'const A<T>' of deduction guide is not a specialization of template 'A'}}
3838

3939
// A deduction-guide shall be declared in the same scope as the corresponding
@@ -71,3 +71,13 @@ namespace WrongScope {
7171
Local(int) -> Local<int>; // expected-error {{expected}}
7272
}
7373
}
74+
75+
namespace GH54909 {
76+
template <typename T> struct A {};
77+
A(void) -> A<int>;
78+
79+
template <typename T> using B = A<T>;
80+
template <typename T> using C = B<T>;
81+
template <typename T> using D = C<T>;
82+
template <typename T> A(T) -> D<T>;
83+
}

0 commit comments

Comments
 (0)