[clang][ASTMatchers] Fix `hasArraySize` crash without a size expression (#215082)

CXXNewExpr::getArraySize() returns std::nullopt even when isArray() is
true, e.g. when there is no array size expression, as in 'new int[]()'.
The hasArraySize matcher dereferenced the optional unconditionally,
triggering undefined behavior (an assertion failure in assert-enabled
builds). Check the optional for engagement before matching.

Since getArraySize() already returns std::nullopt when isArray() is
false, the redundant isArray() check can be dropped.

Add a clang-tidy regression test that runs clang-tidy on a translation
unit containing 'new int[]()', which emits a compiler diagnostic but
must not crash the tool, and document the fix in the release notes.

Fixes #214281

GitOrigin-RevId: b595a746983b828c40140df53fe01eb76c6044f4
2 files changed