Author: Richard Smith Date: 2020-03-11T11:35:13+01:00 New Revision: 5b5a111c6794a0bb0385d04721ea854dd56da357
URL: https://github.com/llvm/llvm-project/commit/5b5a111c6794a0bb0385d04721ea854dd56da357 DIFF: https://github.com/llvm/llvm-project/commit/5b5a111c6794a0bb0385d04721ea854dd56da357.diff LOG: PR45124: Don't leave behind pending cleanups when declaring implicit deduction guides. Previously if an implicit deduction guide had a default argument with a cleanup, we'd leave the 'pending cleanup' flag set after declaring the implicit guide. But it turns out that there's no reason to even substitute into the default argument when declaring an implicit deduction guide: we only need to record that the default argument exists, not what it is, since we never actually form a call to a deduction guide. (cherry picked from commit 6d894afdea433879f54e5ba07e827db006645b7b) Added: Modified: clang/lib/Sema/SemaTemplate.cpp clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index ad4ea2d2593d..b2f0b96b3e62 100755 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2173,9 +2173,15 @@ struct ConvertConstructorToDeductionGuideTransform { // constructor. ExprResult NewDefArg; if (OldParam->hasDefaultArg()) { - NewDefArg = SemaRef.SubstExpr(OldParam->getDefaultArg(), Args); - if (NewDefArg.isInvalid()) - return nullptr; + // We don't care what the value is (we won't use it); just create a + // placeholder to indicate there is a default argument. + QualType ParamTy = NewDI->getType(); + NewDefArg = new (SemaRef.Context) + OpaqueValueExpr(OldParam->getDefaultArg()->getBeginLoc(), + ParamTy.getNonLValueExprType(SemaRef.Context), + ParamTy->isLValueReferenceType() ? VK_LValue : + ParamTy->isRValueReferenceType() ? VK_XValue : + VK_RValue); } ParmVarDecl *NewParam = ParmVarDecl::Create(SemaRef.Context, DC, diff --git a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index 85312cf1049f..2a3f312ebd8e 100644 --- a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -507,6 +507,21 @@ umm m(1); } +namespace PR45124 { + class a { int d; }; + class b : a {}; + + struct x { ~x(); }; + template<typename> class y { y(x = x()); }; + template<typename z> y(z)->y<z>; + + // Not a constant initializer, but trivial default initialization. We won't + // detect this as trivial default initialization if synthesizing the implicit + // deduction guide 'template<typename T> y(x = x()) -> Y<T>;' leaves behind a + // pending cleanup. + __thread b g; +} + #else // expected-no-diagnostics _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits