[all-commits] [llvm/llvm-project] f6c927: [Clang] Improve diagnostics for 'placement new' wi...

Baranov Victor via All-commits all-commits at lists.llvm.org
Fri Jul 11 23:58:28 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f6c927e8dbe8e760c5d21c52f0c211ab3fb58735
      https://github.com/llvm/llvm-project/commit/f6c927e8dbe8e760c5d21c52f0c211ab3fb58735
  Author: Baranov Victor <bar.victor.2002 at gmail.com>
  Date:   2025-07-12 (Sat, 12 Jul 2025)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Sema/SemaExprCXX.cpp
    M clang/test/SemaCXX/new-delete.cpp

  Log Message:
  -----------
  [Clang] Improve diagnostics for 'placement new' with const storage argument (#144270)

Before this patch, the following code gave misleading diagnostics about
absence of `#include <new>`:
```cpp
#include <new>

struct X { int n; };
int foo() {
  const X cx = {5};
  // error: no matching 'operator new' function for non-allocating placement new expression; include <new>
  (void)new(&cx) X{10};
};
```
Now it gives correct diagnostics about constness of passed argument:
```cpp
#include <new>

struct X { int n; };
int foo() {
  const X cx = {5};
  // error: placement new expression with a const-qualified argument of type 'const X *' is not allowed
  (void)new(&cx) X{10};
};
```

Fixes https://github.com/llvm/llvm-project/issues/143708.

---------

Co-authored-by: Corentin Jabot <corentinjabot at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list