Skip to content

Commit 858649a

Browse files
authored
[Clang] Profile singly-resolved UnresolvedLookupExpr with the declaration (#140029)
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. Fixes #139476
1 parent fd85ffb commit 858649a

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
@@ -734,6 +734,7 @@ Bug Fixes to C++ Support
734734
- Fixed the handling of pack indexing types in the constraints of a member function redeclaration. (#GH138255)
735735
- Clang now correctly parses arbitrary order of ``[[]]``, ``__attribute__`` and ``alignas`` attributes for declarations (#GH133107)
736736
- Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852)
737+
- Fixed a function declaration mismatch that caused inconsistencies between concepts and variable template declarations. (#GH139476)
737738
- Clang no longer segfaults when there is a configuration mismatch between modules and their users (http://crbug.com/400353616).
738739
- Fix an incorrect deduction when calling an explicit object member function template through an overload set address.
739740

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
@@ -853,3 +853,18 @@ template <int... Ts>
853853
requires C<Ts...[0]>
854854
auto TplClass<int>::buggy() -> void {}
855855
}
856+
857+
namespace GH139476 {
858+
859+
namespace moo {
860+
template <typename T>
861+
constexpr bool baa = true;
862+
863+
template <typename T> requires baa<T>
864+
void caw();
865+
}
866+
867+
template <typename T> requires moo::baa<T>
868+
void moo::caw() {}
869+
870+
}

0 commit comments

Comments
 (0)