Clang allows arrays of overaligned elements where the alignment and the size does not share the usual relationship (size is an integer multiple of the alignment) with no diagnostic message whatsoever (-Wall -Wextra -Weverything -pedantic-errors) even though such arrays break expectations one way or another and GCC has (since at least 4.1.2) disallowed at least cases where the size is less then the alignment.
In terms of possible ways to realize such an array, either the elements are not necessarily all aligned to the higher alignment or the size of the array must be larger than the size of the elements multiplied by the number of elements. Clang implements the former and GCC (as of 11.x) avoids both.
Clang allows arrays of overaligned elements where the alignment and the size does not share the usual relationship (size is an integer multiple of the alignment) with no diagnostic message whatsoever (
-Wall -Wextra -Weverything -pedantic-errors
) even though such arrays break expectations one way or another and GCC has (since at least 4.1.2) disallowed at least cases where the size is less then the alignment.In terms of possible ways to realize such an array, either the elements are not necessarily all aligned to the higher alignment or the size of the array must be larger than the size of the elements multiplied by the number of elements. Clang implements the former and GCC (as of 11.x) avoids both.
Compiler Explorer link: https://godbolt.org/z/hYzn8jx4b
Source:
Compiler invocation:
clang -cc1 -fsyntax-only -Wall -Wextra -Weverything -pedantic-errors -x c -
Expected behaviour: Diagnostic messages for array elements with sizes that are not an integer multiple of their alignment
Actual behaviour: Compiles successfully with no diagnostics
Compiler version info (
clang -v
):