Document: N1910
Date: 2015-02-25
Author: Rajan Bhakta
Subject: Potential DR: _Alignof Incomplete Arrays
Consider the following code:
int main(void) {
size_t a = _Alignof(int[]); // Why is this not allowed?
return (int)a;
}
6.2.5 #22 says an array of unknown size is an incomplete type.
6.5.3.4 #1 says _Alignof is not allowed for incomplete types. This means the case above is invalid and should be diagnosed (violates a constraint).
6.5.3.4 #3 says for arrays, _Alignof gives the alignment of the element type. No restriction on the completeness of arrays here.
There does not seem to be a reason why incomplete arrays should be disallowed.
Note that C++ dealt with this issue under Core Issue 930, where they changed to allow the operand type of _Alignof to be an incomplete array type.
For C++ compatibility reasons, this should be considered a DR.
Suggested Technical Corrigendum
Change 6.5.3.4 #1 from:
The _Alignof operator shall not be applied to a function type or an incomplete type.
to:
The _Alignof operator shall not be applied to a function type or an incomplete type unless the incomplete type is an array.