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;
         }
----------------
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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73020/new/

https://reviews.llvm.org/D73020



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to