﻿id	summary	reporter	owner	description	type	status	priority	component	version	resolution	keywords	cc
286	typeof Decays Array Types	ajbeach		"C (and hence CFA) does have a habit of replacing arrays with pointers. However there are a few places it should not be decomposed and one of those is inside a typeof. In some cases this does appear to be happening.

I did some simple checks inside sizeof (and repeated them in alignof, but they just play out exactly the same) that looks like this:
{{{
char array[2];

_Static_assert(sizeof(char[2]) == 2 * sizeof(char));
_Static_assert(sizeof(typeof(char[2])) == 2 * sizeof(char));
_Static_assert(sizeof(array) == 2 * sizeof(char));
_Static_assert(sizeof(typeof(array)) == 2 * sizeof(char));

_Static_assert(alignof(char[2]) == alignof(char));
_Static_assert(alignof(typeof(char[2])) == alignof(char));
_Static_assert(alignof(array) == alignof(char));
_Static_assert(alignof(typeof(array)) == alignof(char));
}}}
The first two cases, where we examine the type directly, play out as you would expect, when translation is done the wrapped type is still char[2]. Similarly, in the third case, the sizeof(array) remains unchanged. Only in the forth case sizeof(typeof(array)) is converted to sizeof(char *) which gives the incorrect result.

This is not limited to the operators-on-types, here is a case where it happens as a direct type in a declaration. Checking the translated code confirms that ptr is in fact a pointer to character type.
{{{
int main(int argc, char * argv[]) {
    char array[2] = {5, 7};
    typeof(array) ptr;
    ptr = &array[1];
}
}}}"	defect	closed	major	cfa-cc	1.0	fixed		
