https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86878
Bug ID: 86878 Summary: G++ should warn about invalid alignments passed to allocation functions Product: gcc Version: 9.0 Status: UNCONFIRMED Keywords: diagnostic Severity: enhancement Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- #include <new> __attribute__ ((__alloc_align__(2))) void* alloc(std::size_t, std::size_t); int main() { (void) alloc(10, 5); (void) ::operator new(10, std::align_val_t{5}); } This compiles without diagnostics, but should produce two warnings because 5 is not a power of two and so is not a valid alignment. The attribute means that the call to alloc(10, 5) returns memory aligned to 5, which seems unlikely. I think the attribute should imply that the argument is a valid alignment. It's undefined to call that operator new with a value that is not a valid alignment, so a warning is definitely warranted there.