From: Gauthier Harnisch Date: Fri, 14 Jun 2019 08:40:04 +0000 (+0000) Subject: [clang] Fixing incorrect implicit deduction guides (PR41549) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4a58b8483cde0d2ea84c2ad9741c83b45ede8f55;p=clang [clang] Fixing incorrect implicit deduction guides (PR41549) Summary: [[ https://bugs.llvm.org/show_bug.cgi?id=41549 | bug report ]] Before this patch, implicit deduction guides were generated from the first declaration found by lookup. With this patch implicit deduction guides are generated from the definition of the class template. Also added test that was previously failing. Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits, Quuxplusone Tags: #clang Differential Revision: https://reviews.llvm.org/D63072 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363361 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 2483a28b25..f7f3ccc3e2 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2052,6 +2052,12 @@ private: void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template, SourceLocation Loc) { + if (CXXRecordDecl *DefRecord = + cast(Template->getTemplatedDecl())->getDefinition()) { + TemplateDecl *DescribedTemplate = DefRecord->getDescribedClassTemplate(); + Template = DescribedTemplate ? DescribedTemplate : Template; + } + DeclContext *DC = Template->getDeclContext(); if (DC->isDependentContext()) return; diff --git a/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index 29adc8f560..c5deb9fe91 100644 --- a/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -489,6 +489,21 @@ static_assert(__is_same(decltype(ta), TestSuppression), ""); } #pragma clang diagnostic pop +namespace PR41549 { + +template struct umm; + +template +struct umm { + umm(H h = 0, P p = 0); +}; + +template struct umm; + +umm m(1); + +} + #else // expected-no-diagnostics