From 5a25cad3b3b3afcd50bc576544e5ec029e9f57a6 Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Sat, 13 Sep 2025 16:10:39 +0800 Subject: [PATCH 1/2] [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. --- clang/lib/Sema/SemaTemplateDeduction.cpp | 2 +- clang/test/SemaTemplate/concepts.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 64be2aab259f5..62e867c44ad14 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5180,7 +5180,7 @@ static bool CheckDeducedPlaceholderConstraints(Sema &S, const AutoType &Type, TemplateArgs.addArgument(TypeLoc.getArgLoc(I)); Sema::CheckTemplateArgumentInfo CTAI; - if (S.CheckTemplateArgumentList(Concept, SourceLocation(), TemplateArgs, + if (S.CheckTemplateArgumentList(Concept, TypeLoc.getNameLoc(), TemplateArgs, /*DefaultArgs=*/{}, /*PartialTemplateArgs=*/false, CTAI)) return true; diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp index d63ad01b35800..209e7dc69797d 100644 --- a/clang/test/SemaTemplate/concepts.cpp +++ b/clang/test/SemaTemplate/concepts.cpp @@ -1251,6 +1251,27 @@ int i = SVGPropertyOwnerRegistry::fastAnimatedPropertyLookup() } +namespace GH61824 { + +template // #T_Type +concept C = true; + +constexpr bool f(C auto) { // #GH61824_f + return true; +} + +C auto x = 0; +// expected-error@#T_Type {{type 'int' cannot be used prior to '::'}} \ +// expected-note@-1 {{in instantiation of default argument}} + +// This will be fixed when we merge https://github.com/llvm/llvm-project/pull/141776 +// Which makes us behave like GCC. +static_assert(f(0)); +// expected-error@-1 {{no matching function for call}} \ +// expected-note@#GH61824_f {{constraints not satisfied}} \ +// expected-note@#T_Type {{type 'int' cannot be used prior to '::'}} + +} namespace GH149986 { template concept PerfectSquare = [](){} // expected-note 2{{here}} From 5108b0f36f332eb1bef74dadbf1255fee2114286 Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Sat, 13 Sep 2025 18:00:35 +0800 Subject: [PATCH 2/2] fixup! [Clang] Fix the source location of default template arguments in placeholder constraints --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 51e5973098c14..6eb2a52e80ba9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -285,6 +285,9 @@ Improvements to Clang's diagnostics - Clang now looks through parenthesis for ``-Wundefined-reinterpret-cast`` diagnostic. +- Fixed a bug where the source location was missing when diagnosing ill-formed + placeholder constraints. + Improvements to Clang's time-trace ----------------------------------