From d25c7690621ad26fe03b0c38040ded1e8667372c Mon Sep 17 00:00:00 2001 From: Prathamesh Kulkarni Date: Wed, 20 Jan 2016 16:25:23 +0000 Subject: re PR c/24293 (Undefined behaviour not diagnosed with -fsyntax-only) 2016-01-15 Prathamesh Kulkarni PR c/24293 * c-tree.h (incomplete_record_decls): Declare. * c-parser.c (incomplete_record_decls): Define. (c_parser_translation_unit): Iterate through incomplete_record_decls and report error if any decl has zero size. * c-decl.c (finish_decl): Append static decl with incomplete struct/union or enum type to incomplete_record_decls. testsuite/ * gcc.dg/pr24293.c: New test. * gcc.dg/Wcxx-compat-8.c: Adjust to accept error due to incomplete struct type. * gcc.dg/declspec-1.c: Likewise. * gcc.dg/pr63549.c: Likewise. From-SVN: r232622 --- gcc/c/c-decl.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gcc/c/c-decl.c') diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 5830e22..1ec6042 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -4791,6 +4791,12 @@ finish_decl (tree decl, location_t init_loc, tree init, TREE_TYPE (decl) = error_mark_node; } + if ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)) + || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE) + && DECL_SIZE (decl) == NULL_TREE + && TREE_STATIC (decl)) + incomplete_record_decls.safe_push (decl); + if (is_global_var (decl) && DECL_SIZE (decl) != 0) { if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) -- cgit v1.1