https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/117450
Fixes #54909 >From 5212f12874a859a9f7b6c662402aa2171006d011 Mon Sep 17 00:00:00 2001 From: Oleksandr T <oleksandr.taras...@outlook.com> Date: Sun, 24 Nov 2024 00:19:06 +0200 Subject: [PATCH] [Clang] prevent errors for deduction guides using deduced type aliases --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaDeclCXX.cpp | 6 +++++- clang/test/CXX/temp/temp.deduct.guide/p3.cpp | 12 +++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) 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>; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits