I had an issue similar to this one
gcc over-aligned new support (alignas )
so I added -faligned-new
compiler flag.
This fixed a compiler warning. However, when the compiler is run with --verbose
flag, I get this output https://pastebin.com/X2QZAtSb, in which the most important line is
COLLECT_GCC_OPTIONS='-o' 'main' '-faligned-new=1' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
GCC manual (https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options) states that:
-faligned-new
Enable support for C++17 new of types that require more
alignment than void* ::operator new(std::size_t) provides.
A numeric argument such as -faligned-new=32 can be used to specify how much alignment
(in bytes) is provided by that function, but few users will need to override
the default of alignof(std::max_align_t).
What does -faligned-new=1
mean? If I understand correctly, it should be equal to 8 or 16 or something (default of alignof(std::max_align_t)
, https://en.cppreference.com/w/cpp/types/max_align_t), not 1.
To reproduce compile simple main.cpp:
#include <iostream>
int main() {
std::cout << "hello world\n";
return 0;
}
using g++ main.cpp -o main -faligned-new --verbose
I am compiling the program on GCC 9.3.0, on a Debian system, sizeof(max_align_t)
is 32 on my system.