Skip to content

Commit ed64868

Browse files
committed
Change approach to fixing this.
1 parent 6c8a48b commit ed64868

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

clang/lib/Sema/SemaConcept.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,8 +1743,7 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
17431743
auto IsExpectedEntity = [](const FunctionDecl *FD) {
17441744
FunctionDecl::TemplatedKind Kind = FD->getTemplatedKind();
17451745
return Kind == FunctionDecl::TK_NonTemplate ||
1746-
Kind == FunctionDecl::TK_MemberSpecialization ||
1747-
Kind == FunctionDecl::TK_FunctionTemplateSpecialization;
1746+
Kind == FunctionDecl::TK_FunctionTemplate;
17481747
};
17491748
const auto *FD2 = dyn_cast<FunctionDecl>(D2);
17501749
(void)IsExpectedEntity;

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5805,12 +5805,23 @@ FunctionDecl *Sema::getMoreConstrainedFunction(FunctionDecl *FD1,
58055805
FunctionDecl *FD2) {
58065806
assert(!FD1->getDescribedTemplate() && !FD2->getDescribedTemplate() &&
58075807
"not for function templates");
5808-
FunctionDecl *F1 = FD1;
5809-
if (FunctionDecl *MF = FD1->getInstantiatedFromMemberFunction())
5810-
F1 = MF;
5811-
FunctionDecl *F2 = FD2;
5812-
if (FunctionDecl *MF = FD2->getInstantiatedFromMemberFunction())
5813-
F2 = MF;
5808+
5809+
auto getTemplatePattern = [](FunctionDecl *FD) {
5810+
// Specializations of conversion function templates are believed to be the
5811+
// only case where a function template specialization reaches here.
5812+
assert(!FD->isFunctionTemplateSpecialization() ||
5813+
isa<CXXConversionDecl>(FD));
5814+
5815+
if (FunctionDecl *MF = FD->getInstantiatedFromMemberFunction())
5816+
return MF;
5817+
else if (FunctionTemplateDecl *FTD = FD->getPrimaryTemplate())
5818+
return FTD->getTemplatedDecl();
5819+
5820+
return FD;
5821+
};
5822+
FunctionDecl *F1 = getTemplatePattern(FD1);
5823+
FunctionDecl *F2 = getTemplatePattern(FD2);
5824+
58145825
llvm::SmallVector<const Expr *, 1> AC1, AC2;
58155826
F1->getAssociatedConstraints(AC1);
58165827
F2->getAssociatedConstraints(AC2);

clang/test/SemaCXX/PR98671.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify
22

3-
struct S {
3+
struct S1 {
44
operator int();
55

66
template <typename T>
@@ -10,5 +10,19 @@ struct S {
1010

1111
// Ensure that no assertion is raised when overload resolution fails while
1212
// choosing between an operator function template and an operator function.
13-
constexpr auto r = &S::operator int;
13+
constexpr auto r = &S1::operator int;
1414
// expected-error@-1 {{initializer of type '<overloaded function type>'}}
15+
16+
17+
template <typename T>
18+
struct S2 {
19+
template <typename U=T>
20+
S2(U={}) requires (sizeof(T) > 0) {}
21+
// expected-note@-1 {{candidate constructor}}
22+
23+
template <typename U=T>
24+
S2(U={}) requires (true) {}
25+
// expected-note@-1 {{candidate constructor}}
26+
};
27+
28+
S2<int> s; // expected-error {{call to constructor of 'S2<int>' is ambiguous}}

0 commit comments

Comments
 (0)