Skip to content

Commit 2c2ad9a

Browse files
authored
Reapply "[Clang] Profile singly-resolved UnresolvedLookupExpr with the declaration" (#140680)
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 profiles the underlying VarTemplateDecl if UnresolvedLookupExpr is used to model a dependent use of it. Fixes #139476
1 parent 03461c9 commit 2c2ad9a

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ Bug Fixes to C++ Support
852852
- Fixed the handling of pack indexing types in the constraints of a member function redeclaration. (#GH138255)
853853
- Clang now correctly parses arbitrary order of ``[[]]``, ``__attribute__`` and ``alignas`` attributes for declarations (#GH133107)
854854
- Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852)
855+
- Fixed a function declaration mismatch that caused inconsistencies between concepts and variable template declarations. (#GH139476)
855856
- Clang no longer segfaults when there is a configuration mismatch between modules and their users (http://crbug.com/400353616).
856857
- Fix an incorrect deduction when calling an explicit object member function template through an overload set address.
857858
- Fixed bug in constant evaluation that would allow using the value of a

clang/lib/AST/StmtProfile.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,8 +2189,14 @@ StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
21892189

21902190
void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
21912191
VisitExpr(S);
2192-
VisitNestedNameSpecifier(S->getQualifier());
2193-
VisitName(S->getName(), /*TreatAsDecl*/ true);
2192+
bool DescribingDependentVarTemplate =
2193+
S->getNumDecls() == 1 && isa<VarTemplateDecl>(*S->decls_begin());
2194+
if (DescribingDependentVarTemplate) {
2195+
VisitDecl(*S->decls_begin());
2196+
} else {
2197+
VisitNestedNameSpecifier(S->getQualifier());
2198+
VisitName(S->getName(), /*TreatAsDecl*/ true);
2199+
}
21942200
ID.AddBoolean(S->hasExplicitTemplateArgs());
21952201
if (S->hasExplicitTemplateArgs())
21962202
VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());

clang/test/SemaCXX/exception-spec.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,24 @@ namespace AssignmentOp {
5252
D2 &operator=(const D2&); // expected-error {{more lax}}
5353
};
5454
}
55+
56+
namespace OverloadedFunctions {
57+
58+
template <typename T>
59+
void f(T&) noexcept;
60+
61+
template <typename T, int N>
62+
void f(T (&arr)[N]) noexcept(noexcept(f(*arr)));
63+
64+
template <typename T>
65+
inline void f(T&) noexcept {}
66+
67+
template <typename T, int N>
68+
inline void f(T (&arr)[N]) noexcept(noexcept(f(*arr))) {}
69+
70+
void g() {
71+
int x[1];
72+
f(x);
73+
}
74+
75+
}

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)