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

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 24 01:28:51 PDT 2026


================
@@ -0,0 +1,72 @@
+//===- DynamicAllocationArgumentsCXX.h - operator new/delete args ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the argument candidate and resolution types for operators
+// new and new[] overload resolution.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SEMA_DYNAMICALLOCATIONARGUMENTSCXX_H
+#define LLVM_CLANG_SEMA_DYNAMICALLOCATIONARGUMENTSCXX_H
+
+#include "clang/AST/ExprCXX.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace clang {
+
+class LookupResult;
+class Sema;
+
+struct ImplicitAllocationArguments {
+  friend Sema;
+
+  ArrayRef<Expr *> getImplicitArguments() const {
+    return ArrayRef(ImplicitArguments, ArgumentCount);
+  }
+
+  Expr *getAlignmentArgument() const {
+    if (PassAlignment == AlignedAllocationMode::Yes)
+      return ImplicitArguments[ArgumentCount - 1];
+    return nullptr;
+  }
+
+  void updateLookupForMSVCCompatibility(Sema &, LookupResult &);
+  TypeAwareAllocationMode PassTypeIdentity;
+  AlignedAllocationMode PassAlignment;
+
+private:
+  ImplicitAllocationArguments(Sema &SemaRef, Expr *TypeIdentityArg,
+                              Expr *SizeArg, Expr *AlignArg,
+                              bool IsMSVCCompatibilityFallback);
----------------
ojhunt wrote:

I don't see the value in a default argument for a very small set of callers, all of whom are new. I would rather be explicit and only reluctantly switched to a bool rather than an enum :D

I like very explicit code unless I think there's a strong argument to the contrary, and this case didn't seem to warrant the brevity of a default arg.

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


More information about the cfe-commits mailing list