Tyker created this revision. Tyker added a reviewer: rsmith. Herald added a project: clang. Herald added a subscriber: cfe-commits.
bug report <https://bugs.llvm.org/show_bug.cgi?id=41549> 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. Repository: rC Clang https://reviews.llvm.org/D63072 Files: clang/lib/Sema/SemaTemplate.cpp clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp =================================================================== --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -489,6 +489,21 @@ } #pragma clang diagnostic pop +namespace PR41549 { + +template <class H, class P> struct umm; + +template <class H = int, class P = int> +struct umm { + umm(H h = 0, P p = 0); +}; + +template <class H, class P> struct umm; + +umm<> m(1); + +} + #else // expected-no-diagnostics Index: clang/lib/Sema/SemaTemplate.cpp =================================================================== --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2052,6 +2052,12 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template, SourceLocation Loc) { + if (CXXRecordDecl *DefRecord = + cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) { + TemplateDecl *DescribedTemplate = DefRecord->getDescribedClassTemplate(); + Template = DescribedTemplate ? DescribedTemplate : Template; + } + DeclContext *DC = Template->getDeclContext(); if (DC->isDependentContext()) return;
Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp =================================================================== --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -489,6 +489,21 @@ } #pragma clang diagnostic pop +namespace PR41549 { + +template <class H, class P> struct umm; + +template <class H = int, class P = int> +struct umm { + umm(H h = 0, P p = 0); +}; + +template <class H, class P> struct umm; + +umm<> m(1); + +} + #else // expected-no-diagnostics Index: clang/lib/Sema/SemaTemplate.cpp =================================================================== --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2052,6 +2052,12 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template, SourceLocation Loc) { + if (CXXRecordDecl *DefRecord = + cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) { + TemplateDecl *DescribedTemplate = DefRecord->getDescribedClassTemplate(); + Template = DescribedTemplate ? DescribedTemplate : Template; + } + DeclContext *DC = Template->getDeclContext(); if (DC->isDependentContext()) return;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits