Skip to content

Commit debef50

Browse files
committed
[Clang] Profile singly-resolved UnresolvedLookupExpr with the declaration
For a dependent variable template specialization, we don't build a dependent Decl node or a DeclRefExpr to represent it. Instead, we preserve the UnresolvedLookupExpr until instantiation. However, this approach isn't ideal for constraint normalization. We consider the qualifier during profiling, but since that's based on the written code, it can introduce confusing differences, even when the expressions resolve to the same declaration. This change ensures that, if possible, we profile the resolved declaration instead of its qualifier. For expressions that resolve to more than one declarations, we still profile its qualifier, as otherwise it would make us depend on the order of lookup results.
1 parent cbf10c2 commit debef50

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ Bug Fixes to C++ Support
545545
- Clang no longer crashes when establishing subsumption between some constraint expressions. (#GH122581)
546546
- Clang now issues an error when placement new is used to modify a const-qualified variable
547547
in a ``constexpr`` function. (#GH131432)
548+
- Fixed a function declaration mismatch that caused inconsistencies between concepts and variable template declarations. (#GH139476)
548549
- Clang now emits a warning when class template argument deduction for alias templates is used in C++17. (#GH133806)
549550

550551
Bug Fixes to AST Handling

clang/lib/AST/StmtProfile.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,10 @@ StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
21892189

21902190
void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
21912191
VisitExpr(S);
2192-
VisitNestedNameSpecifier(S->getQualifier());
2192+
if (S->getNumDecls() == 1)
2193+
VisitDecl(*S->decls_begin());
2194+
else
2195+
VisitNestedNameSpecifier(S->getQualifier());
21932196
VisitName(S->getName(), /*TreatAsDecl*/ true);
21942197
ID.AddBoolean(S->hasExplicitTemplateArgs());
21952198
if (S->hasExplicitTemplateArgs())

clang/test/SemaTemplate/concepts-out-of-line-def.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,3 +779,18 @@ template <typename T>
779779
consteval void S::mfn() requires (bool(&fn)) {}
780780

781781
}
782+
783+
namespace GH139476 {
784+
785+
namespace moo {
786+
template <typename T>
787+
constexpr bool baa = true;
788+
789+
template <typename T> requires baa<T>
790+
void caw();
791+
}
792+
793+
template <typename T> requires moo::baa<T>
794+
void moo::caw() {}
795+
796+
}

0 commit comments

Comments
 (0)