Fix handling of deleted and templated constructors. (#6129)

Don't ignore deleted constructors in overload resolution. If one is the
best match, we want an error rather than picking something else. Don't
crash if we find a constructor template or other weird thing; use
`getConstructorInfo` to map it into a constructor and skip it if it
isn't one, like Clang does.
This commit is contained in:
Richard Smith
2025-09-25 04:19:18 +00:00
committed by GitHub
parent 1fba60ca8c
commit d85781acbf
2 changed files with 240 additions and 11 deletions
+5 -4
View File
@@ -21,6 +21,7 @@
#include "clang/Frontend/TextDiagnostic.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Overload.h"
#include "common/check.h"
#include "common/ostream.h"
#include "common/raw_string_ostream.h"
@@ -2117,12 +2118,12 @@ static auto ImportConstructorsIntoScope(Context& context, SemIR::LocId loc_id,
ClangConstructorLookup(context, scope_id);
clang::UnresolvedSet<4> overload_set;
for (clang::Decl* decl : constructors_lookup) {
auto* constructor = cast<clang::CXXConstructorDecl>(decl);
if (constructor->isDeleted() || constructor->isCopyOrMoveConstructor()) {
for (auto* decl : constructors_lookup) {
auto info = clang::getConstructorInfo(decl);
if (!info.Constructor || info.Constructor->isCopyOrMoveConstructor()) {
continue;
}
overload_set.addDecl(constructor, constructor->getAccess());
overload_set.addDecl(info.FoundDecl, info.FoundDecl->getAccess());
}
if (overload_set.empty()) {
return SemIR::ScopeLookupResult::MakeNotFound();