From: Richard Smith Date: Mon, 22 Jun 2020 23:45:12 +0000 (-0700) Subject: Fix multilevel deduction where an outer pack is used in the type of an X-Git-Tag: llvmorg-12-init~2290 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=009c9b83acfc8bb863894e349bccc2473c685dbc;p=platform%2Fupstream%2Fllvm.git Fix multilevel deduction where an outer pack is used in the type of an inner non-type pack at a different index. We previously considered the index of the outer pack (which would refer to an unrelated template parameter) to be deduced by deducing the inner pack, because we inspected the (largely meaningless) type of an expanded non-type template parameter pack. --- diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 877020ed..e6569d4a 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -738,8 +738,9 @@ private: // type, so we need to collect the pending deduced values for those packs. if (auto *NTTP = dyn_cast( TemplateParams->getParam(Index))) { - if (auto *Expansion = dyn_cast(NTTP->getType())) - ExtraDeductions.push_back(Expansion->getPattern()); + if (!NTTP->isExpandedParameterPack()) + if (auto *Expansion = dyn_cast(NTTP->getType())) + ExtraDeductions.push_back(Expansion->getPattern()); } // FIXME: Also collect the unexpanded packs in any type and template // parameter packs that are pack expansions. diff --git a/clang/test/SemaTemplate/deduction-guide.cpp b/clang/test/SemaTemplate/deduction-guide.cpp index c1ce625..3ac37ac 100644 --- a/clang/test/SemaTemplate/deduction-guide.cpp +++ b/clang/test/SemaTemplate/deduction-guide.cpp @@ -1,14 +1,14 @@ // RUN: %clang_cc1 -std=c++2a -verify -ast-dump -ast-dump-decl-types -ast-dump-filter "deduction guide" %s | FileCheck %s +// expected-no-diagnostics template struct X {}; -template struct A { // expected-note 2{{candidate}} - template A(X, Ts (*...qs)[Ns]); // expected-note {{candidate}} +template struct A { + template A(X, Ts (*...qs)[Ns]); }; int arr1[3], arr2[3]; short arr3[4]; -// FIXME: The CTAD deduction here succeeds, but the initialization deduction spuriously fails. -A a(X<&arr1, &arr2>{}, &arr1, &arr2, &arr3); // FIXME: expected-error {{no matching constructor}} +A a(X<&arr1, &arr2>{}, &arr1, &arr2, &arr3); using AT = decltype(a); using AT = A;