Skip to content

Commit 9ac2924

Browse files
authored
[Clang] Fix the source location of default template arguments in placeholder constraints (#158414)
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 is involved by the substitution of default template arguments that happens before constraint evaluation. See the issue alive: https://godbolt.org/z/cWr9qP3E8
1 parent b31f8cb commit 9ac2924

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ Improvements to Clang's diagnostics
285285

286286
- Clang now looks through parenthesis for ``-Wundefined-reinterpret-cast`` diagnostic.
287287

288+
- Fixed a bug where the source location was missing when diagnosing ill-formed
289+
placeholder constraints.
290+
288291
Improvements to Clang's time-trace
289292
----------------------------------
290293

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)