Skip to content

[clang][bytecode] Loosen an assertion about operator delete#200575

Merged
tbaederr merged 1 commit into
llvm:mainfrom
tbaederr:operator-delete2
May 30, 2026
Merged

[clang][bytecode] Loosen an assertion about operator delete#200575
tbaederr merged 1 commit into
llvm:mainfrom
tbaederr:operator-delete2

Conversation

@tbaederr
Copy link
Copy Markdown
Contributor

We may also see OO_Array_Delete here.

@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels May 30, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

We may also see OO_Array_Delete here.


Full diff: https://github.com/llvm/llvm-project/pull/200575.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3-1)
  • (modified) clang/test/AST/ByteCode/new-delete.cpp (+15)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 88515edb660a9..f0d047ad01632 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5733,7 +5733,9 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
     if (FuncDecl->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
       if (FuncDecl->getDeclName().isAnyOperatorNew())
         return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_new);
-      assert(FuncDecl->getDeclName().getCXXOverloadedOperator() == OO_Delete);
+      assert(FuncDecl->getDeclName().getCXXOverloadedOperator() == OO_Delete ||
+             FuncDecl->getDeclName().getCXXOverloadedOperator() ==
+                 OO_Array_Delete);
       return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_delete);
     }
 
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index b6e6d333a4bcb..22dc2e5d692e1 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -1217,6 +1217,21 @@ namespace ArrayDestSize {
   static_assert(dynarray<char>(3, 2) == 'x'); // both-error {{constant expression}} both-note {{in call}}
 }
 
+namespace OpertorArrayDelete {
+  struct S {};
+  using State = S[2];
+  constexpr unsigned run(const State *s) {
+    void *p;
+    p = operator new[](128); // both-note {{cannot allocate untyped memory}}
+    operator delete[](p);
+    return 42;
+  }
+
+  constexpr State s[] = {};
+  static_assert(run(s) == 42, ""); // both-error {{not an integral constant expression}} \
+                                   // both-note {{in call to}}
+}
+
 #else
 /// Make sure we reject this prior to C++20
 constexpr int a() { // both-error {{never produces a constant expression}}

@tbaederr tbaederr merged commit 470411c into llvm:main May 30, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant