[PATCH] D73020: [Sema] Perform call checking when building CXXNewExpr
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 4 14:32:51 PST 2020
lebedev.ri marked 3 inline comments as done.
lebedev.ri added inline comments.
================
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;
}
----------------
lebedev.ri wrote:
> rsmith wrote:
> > 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>();
> > ```
> Hmm.
> I'll post that as a followup patch here.
Posted D73996.
I'm not sure which cases should remain as error?
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