Skip to content

Commit 5a25cad

Browse files
committed
[Clang] Fix the source location of default template arguments in placeholder constraints
We discovered this issue while working on the concept normalization refactoring. We missed the source location when diagnosing the instantiation point of the placeholder constraints, which happened in the substitution of default template arguments that happened earlier than constraint evaluation.
1 parent fd58f23 commit 5a25cad

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5180,7 +5180,7 @@ static bool CheckDeducedPlaceholderConstraints(Sema &S, const AutoType &Type,
51805180
TemplateArgs.addArgument(TypeLoc.getArgLoc(I));
51815181

51825182
Sema::CheckTemplateArgumentInfo CTAI;
5183-
if (S.CheckTemplateArgumentList(Concept, SourceLocation(), TemplateArgs,
5183+
if (S.CheckTemplateArgumentList(Concept, TypeLoc.getNameLoc(), TemplateArgs,
51845184
/*DefaultArgs=*/{},
51855185
/*PartialTemplateArgs=*/false, CTAI))
51865186
return true;

clang/test/SemaTemplate/concepts.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,27 @@ int i = SVGPropertyOwnerRegistry<SVGCircleElement>::fastAnimatedPropertyLookup()
12511251

12521252
}
12531253

1254+
namespace GH61824 {
1255+
1256+
template<typename T, typename U = typename T::type> // #T_Type
1257+
concept C = true;
1258+
1259+
constexpr bool f(C auto) { // #GH61824_f
1260+
return true;
1261+
}
1262+
1263+
C auto x = 0;
1264+
// expected-error@#T_Type {{type 'int' cannot be used prior to '::'}} \
1265+
// expected-note@-1 {{in instantiation of default argument}}
1266+
1267+
// This will be fixed when we merge https://github.com/llvm/llvm-project/pull/141776
1268+
// Which makes us behave like GCC.
1269+
static_assert(f(0));
1270+
// expected-error@-1 {{no matching function for call}} \
1271+
// expected-note@#GH61824_f {{constraints not satisfied}} \
1272+
// expected-note@#T_Type {{type 'int' cannot be used prior to '::'}}
1273+
1274+
}
12541275

12551276
namespace GH149986 {
12561277
template <typename T> concept PerfectSquare = [](){} // expected-note 2{{here}}

0 commit comments

Comments
 (0)