llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) <details> <summary>Changes</summary> Fixes #<!-- -->54909 --- Full diff: https://github.com/llvm/llvm-project/pull/117450.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/lib/Sema/SemaDeclCXX.cpp (+5-1) - (modified) clang/test/CXX/temp/temp.deduct.guide/p3.cpp (+11-1) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8bd06fadfdc984..2437def6322764 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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 ---------------------------------- diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 26041e53de5061..9d0eb098841a3a 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -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); diff --git a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp index c5404847beb066..36e0f75ccf9098 100644 --- a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp +++ b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp @@ -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 @@ -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>; +} `````````` </details> https://github.com/llvm/llvm-project/pull/117450 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits