[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


================
@@ -7,8 +7,9 @@ void *operator new(size_t); // #new_decl
 struct Tag {};
 
 void f() {
-  int *p = new (Tag{}) int[4];
-  // expected-error at -1 {{no matching function for call to 'operator new'}}
+  int *p = new (Tag{}) int[4]; // #new_expr
+  // expected-error@#new_expr {{no matching function for call to 'operator new[]'}}
   // expected-note@#new_decl {{candidate function not viable: requires 1 argument, but 2 were provided}}
+  // expected-note@#new_expr {{MSVC compatibility fall back to 'operator new' failed}}
----------------
igorkudrin wrote:

Isn't this even more confusing? With this change, it now reads like the compiler tried to find 'operator new[]' but looked only through 'operator new', and failed.

I believe that if the MSVC compatibility fallback failed, the diagnostics should print notes for 'operator new[]' in the first place.

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


More information about the cfe-commits mailing list