[clang] 2b38688 - Reland: [clang] Use getDefaultArgRange instead of getDefaultArg to retrieve
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Sat May 11 13:08:12 PDT 2024
Author: Haojian Wu
Date: 2024-05-11T22:07:21+02:00
New Revision: 2b386888b78327db4906b12401e1a89438471548
URL: https://github.com/llvm/llvm-project/commit/2b386888b78327db4906b12401e1a89438471548
DIFF: https://github.com/llvm/llvm-project/commit/2b386888b78327db4906b12401e1a89438471548.diff
LOG: Reland: [clang] Use getDefaultArgRange instead of getDefaultArg to retrieve
source location in `ConvertConstructorToDeductionGuideTransform`.
The commit fec471649fffaa3ec44e17801e5c9605825e58bb was reverted by accident in 7415524b45392651969374c067041daa82dc89e7.
Reland it with a testcase.
Added:
Modified:
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/ctad.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 82badb2efb5cf..0e7bd8dd89573 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 ec144d4f44ba8..e981ea8d5ecfb 100644
--- a/clang/test/SemaTemplate/ctad.cpp
+++ b/clang/test/SemaTemplate/ctad.cpp
@@ -54,3 +54,18 @@ template<class T, class B> struct Y { Y(T); };
template<class T, class B=void> struct Y ;
Y y(1);
}
+
+namespace NoCrashOnGettingDefaultArgLoc {
+template <typename>
+class A {
+ A(int = 1); // expected-note {{candidate template ignored: couldn't infer template argumen}}
+};
+class C : A<int> {
+ using A::A;
+};
+template <typename>
+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}}
+}
More information about the cfe-commits
mailing list