1

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.

Hcorg
  • 11,598
  • 3
  • 31
  • 36
Dinuirar
  • 25
  • 5

1 Answers1

2

What does -faligned-new=1 mean?

Apparently, it means that -faligned-new was used without explicit threshold.

As per documentation, the threshold defaults to alignment of std::max_align_t in this case.

eerorika
  • 232,697
  • 12
  • 197
  • 326
  • It would be reasonable. However I'd expect that value of this flag reported by the compiler will be `sizeof(std::max_align_t)` (in my case: `=32`). Have you got any sources that GCC really outputs `some_flag_name=1` if it uses a default value? – Dinuirar May 29 '20 at 16:08
  • @Dinuirar Your demonstration is one source. You didn't specify a value, and `--verbose` showed 1. – eerorika May 29 '20 at 16:25