Skip to content

Fix assertion failure during conversion function overload resolution. #98671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ Bug Fixes to C++ Support
- Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667),
(#GH99877).
- Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions.
- Fixed an assertion failure when selecting a function from an overload set that includes a
specialization of a conversion function template.

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
15 changes: 11 additions & 4 deletions clang/lib/Sema/SemaTemplateDeduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5805,12 +5805,19 @@ FunctionDecl *Sema::getMoreConstrainedFunction(FunctionDecl *FD1,
FunctionDecl *FD2) {
assert(!FD1->getDescribedTemplate() && !FD2->getDescribedTemplate() &&
"not for function templates");
assert(!FD1->isFunctionTemplateSpecialization() ||
isa<CXXConversionDecl>(FD1));
assert(!FD2->isFunctionTemplateSpecialization() ||
isa<CXXConversionDecl>(FD2));

FunctionDecl *F1 = FD1;
if (FunctionDecl *MF = FD1->getInstantiatedFromMemberFunction())
F1 = MF;
if (FunctionDecl *P = FD1->getTemplateInstantiationPattern(false))
F1 = P;

FunctionDecl *F2 = FD2;
if (FunctionDecl *MF = FD2->getInstantiatedFromMemberFunction())
F2 = MF;
if (FunctionDecl *P = FD2->getTemplateInstantiationPattern(false))
F2 = P;

llvm::SmallVector<const Expr *, 1> AC1, AC2;
F1->getAssociatedConstraints(AC1);
F2->getAssociatedConstraints(AC2);
Expand Down
28 changes: 28 additions & 0 deletions clang/test/SemaCXX/PR98671.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify

struct S1 {
operator int();

template <typename T>
operator T();
};


// Ensure that no assertion is raised when overload resolution fails while
// choosing between an operator function template and an operator function.
constexpr auto r = &S1::operator int;
// expected-error@-1 {{initializer of type '<overloaded function type>'}}


template <typename T>
struct S2 {
template <typename U=T>
S2(U={}) requires (sizeof(T) > 0) {}
// expected-note@-1 {{candidate constructor}}

template <typename U=T>
S2(U={}) requires (true) {}
// expected-note@-1 {{candidate constructor}}
};

S2<int> s; // expected-error {{call to constructor of 'S2<int>' is ambiguous}}
Loading