[PATCH] D73020: [Sema] Perform call checking when building CXXNewExpr
Richard Smith - zygoloid via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 4 12:42:12 PST 2020
rsmith added a comment.
Looks good if you change the error to a warning.
================
Comment at: clang/lib/Sema/SemaChecking.cpp:3887-3891
if (!I.isPowerOf2()) {
Diag(Arg->getExprLoc(), diag::err_alignment_not_power_of_two)
<< Arg->getSourceRange();
return;
}
----------------
Oh, I wasn't aware we gave an error for this case. We can't issue an error for passing a bad alignment to `operator new` -- it's valid for code to pass a bad alignment, but results in undefined behavior. The same is true for `aligned_alloc` and `posix_memalign`, so we should presumably just downgrade this from an error to a warning in general rather than (say) treating `operator new` as a special case.
For example, this is valid and may be reasonable in some cases:
```
template<int N> void *make() {
if ((N & (N-1)) == 0)
return operator new(N, std::align_val_t(N));
else
return operator new(N);
}
void *p = make<7>();
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73020/new/
https://reviews.llvm.org/D73020
More information about the cfe-commits
mailing list