Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ Improvements to Clang's diagnostics
- For an rvalue reference bound to a temporary struct with an integer member, Clang will detect constant integer overflow
in the initializer for the integer member (#GH46755).

- Clang now prevents errors for deduction guides with deduced type aliases (#GH54909).

Improvements to Clang's time-trace
----------------------------------

Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11451,7 +11451,11 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
bool MightInstantiateToSpecialization = false;
if (auto RetTST =
TSI->getTypeLoc().getAsAdjusted<TemplateSpecializationTypeLoc>()) {
TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName();
const TemplateSpecializationType *TST = RetTST.getTypePtr();
while (TST->isTypeAlias())
TST = TST->getAliasedType()->getAs<TemplateSpecializationType>();

TemplateName SpecifiedName = TST->getTemplateName();
bool TemplateMatches = Context.hasSameTemplateName(
SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true);

Expand Down
12 changes: 11 additions & 1 deletion clang/test/CXX/temp/temp.deduct.guide/p3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template<template<typename> typename TT> struct E { // expected-note 2{{template
};

A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is not a specialization of template 'A'}}
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'}}
template <typename T> A(T)->B<T>;
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'}}

// A deduction-guide shall be declared in the same scope as the corresponding
Expand Down Expand Up @@ -71,3 +71,13 @@ namespace WrongScope {
Local(int) -> Local<int>; // expected-error {{expected}}
}
}

namespace GH54909 {
template <typename T> struct A {};
A(void) -> A<int>;

template <typename T> using B = A<T>;
template <typename T> using C = B<T>;
template <typename T> using D = C<T>;
template <typename T> A(T) -> D<T>;
}
Loading