diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 82badb2efb5cfa..0e7bd8dd89573c 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2679,7 +2679,7 @@ struct ConvertConstructorToDeductionGuideTransform { // placeholder to indicate there is a default argument. QualType ParamTy = NewDI->getType(); NewDefArg = new (SemaRef.Context) - OpaqueValueExpr(OldParam->getDefaultArg()->getBeginLoc(), + OpaqueValueExpr(OldParam->getDefaultArgRange().getBegin(), ParamTy.getNonLValueExprType(SemaRef.Context), ParamTy->isLValueReferenceType() ? VK_LValue : ParamTy->isRValueReferenceType() ? VK_XValue diff --git a/clang/test/SemaTemplate/ctad.cpp b/clang/test/SemaTemplate/ctad.cpp index ec144d4f44ba8c..e981ea8d5ecfbe 100644 --- a/clang/test/SemaTemplate/ctad.cpp +++ b/clang/test/SemaTemplate/ctad.cpp @@ -54,3 +54,18 @@ template struct Y { Y(T); }; template struct Y ; Y y(1); } + +namespace NoCrashOnGettingDefaultArgLoc { +template +class A { + A(int = 1); // expected-note {{candidate template ignored: couldn't infer template argumen}} +}; +class C : A { + using A::A; +}; +template +class D : C { // expected-note {{candidate function template not viable: requires 1 argument}} + using C::C; +}; +D abc; // expected-error {{no viable constructor or deduction guide}} +}