[clang] [clang] Simplify the overload resolution logic for operator new and new[] (PR #211482)

Igor Kudrin via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 27 20:03:31 PDT 2026


================
@@ -2904,50 +2915,52 @@ static void DiagnoseAllocationLookupFailure(
   auto Rerun = [&](ImplicitAllocationArguments &ArgumentList,
                    OverloadCandidateSet &Candidates,
                    SmallVectorImpl<Expr *> &Args) {
+    const LookupResult &LocalLookup =
+        ArgumentList.updateLookupForMSVCCompatibility(SemaRef, BaseLookup,
+                                                      MSVCFallback);
     llvm::append_range(Args, ArgumentList.getImplicitArguments());
     llvm::append_range(Args, PlacementArguments);
     FunctionDecl *Unused = nullptr;
-    resolveAllocationOverload(SemaRef, R, Range, ArgumentList, Args, Unused,
-                              Candidates, /*Diagnose=*/false);
+    resolveAllocationOverload(SemaRef, LocalLookup, Range, ArgumentList, Args,
+                              Unused, Candidates, /*Diagnose=*/false);
   };
   std::optional<OverloadCandidateSet> AlignedCandidates;
   Expr *AlignArg = nullptr;
   if (AlignedArgumentList) {
-    AlignedCandidates.emplace(R.getNameLoc(), OverloadCandidateSet::CSK_Normal);
+    AlignedCandidates.emplace(BaseLookup.getNameLoc(),
+                              OverloadCandidateSet::CSK_Normal);
     SmallVector<Expr *, 4> AlignedArgs;
     Rerun(*AlignedArgumentList, *AlignedCandidates, AlignedArgs);
     AlignArg = AlignedArgumentList->getAlignmentArgument();
   }
-  OverloadCandidateSet UnalignedCandidates(R.getNameLoc(),
+  OverloadCandidateSet UnalignedCandidates(BaseLookup.getNameLoc(),
                                            OverloadCandidateSet::CSK_Normal);
   SmallVector<Expr *, 4> UnalignedArgs;
   Rerun(*UnalignedArgumentList, UnalignedCandidates, UnalignedArgs);
   diagnoseNoViableFunctionForAllocationOverloadResolution(
-      SemaRef, R, Range, UnalignedArgs, UnalignedCandidates,
-      AlignedCandidates ? &*AlignedCandidates : nullptr, AlignArg);
+      SemaRef, BaseLookup, MSVCFallback, Range, UnalignedArgs,
+      UnalignedCandidates, AlignedCandidates ? &*AlignedCandidates : nullptr,
+      AlignArg);
 }
 
-bool Sema::getTypeIdentityArgument(QualType Type, SourceLocation Loc,
-                                   Expr **FoundExpr) {
+std::optional<Expr *> Sema::getTypeIdentityArgument(QualType Type,
----------------
igorkudrin wrote:

The method never returns `std::optional(nullptr)`. Maybe returning just `Expr *` would be enough?

https://github.com/llvm/llvm-project/pull/211482


More information about the cfe-commits mailing list