[clang] Clean up array allocation logic in Sema::BuildCXXNew (PR #186617)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 15 00:52:14 PDT 2026


https://github.com/ojhunt requested changes to this pull request.

I don't believe this is a good change sorry - it's a relatively large abstraction layer to "simplify" maybe two actual expressions.

If we really wanted to do something here I would probably just replace the optional<> with

```cpp
bool IsArraySizeDependent = false;
bool ... = false;
if (ArraySize) {
  set all the "there is an array size" variables as appropriate
}
```

It seems the main concern is the compound conditions, which is consistent with what other code does, but I would prefer to reduce that in general.

But the issue here is not made better with an abstraction (the better option would be actual language support for optional in c++)

I've marked as "request changes" but I think this is probably the wrong tack, and I'm not sure the problem with new/delete Sema is this bit. There's so much more that is so much worse.

While not an option for clang any time soon, I have wondered if reflection could be used in a way to make this kind of thing more expensive.

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


More information about the cfe-commits mailing list