On Fri, Jul 22, 2016 at 10:33:50AM -0400, David Malcolm wrote:
> gcc/cp/ChangeLog:
> * parser.h (struct cp_token): Add a STATIC_ASSERT on the
> size of the struct.
> ---
> gcc/cp/parser.h | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/gcc/cp/parser.h b/gcc/cp/parser.h
> index ccbace9..8c1de57 100644
> --- a/gcc/cp/parser.h
> +++ b/gcc/cp/parser.h
> @@ -71,6 +71,15 @@ struct GTY (()) cp_token {
> "|| (%1.type == CPP_DECLTYPE)"))) u;
> };
>
> +/* The C++ frontend lexes everything first, and keeps the tokens
> + in memory, so there are possibly millions of tokens in memory.
> + Ensure that we don't accidentally grow the structure. */
> +STATIC_ASSERT (sizeof (cp_token) ==
> + (2 // "type" and "keyword"
> + + 1 // "flags"
> + + 1 // bitfields
> + + 4 // location_t
> + + sizeof (void *))); // union
Doesn't that assume way too much on the host data layout?
This can be compiled with weirdo system compilers or on weirdo hosts,
I bet we don't really support non-8-bit char hosts, but still this might
break somewhere...
The formatting is wrong BTW, == shouldn't appear at the end of line.
Jakub