From 4e4620d8c796af482b57b94932618d1f9d9af9f7 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 19 Dec 2022 20:55:56 +0100 Subject: c: Diagnose compound literals with function type [PR108043] Both C99 and latest C2X say that compound literal shall have an object type (complete object type in the latter case) or array of unknown bound, so complit with function type is invalid. When the initializer had to be non-empty for such case, we used to diagnose it as incorrect initializer, but with (fntype){} now allowed we just ICE on it. The following patch diagnoses that. 2022-12-19 Jakub Jelinek PR c/108043 * c-parser.cc (c_parser_postfix_expression_after_paren_type): Diagnose compound literals with function type. * gcc.dg/pr108043.c: New test. * gcc.dg/c99-complit-2.c (foo): Adjust expected diagnostics for complit with function type. --- gcc/c/c-parser.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gcc/c') diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 1bbb39f..7d6960f 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -10924,6 +10924,11 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, error_at (type_loc, "compound literal has variable size"); type = error_mark_node; } + else if (TREE_CODE (type) == FUNCTION_TYPE) + { + error_at (type_loc, "compound literal has function type"); + type = error_mark_node; + } if (constexpr_p && type != error_mark_node) { tree type_no_array = strip_array_types (type); -- cgit v1.1